我想确定我的索引是否位于字边界。
例如在字符串“国家航空航天研究是一个了不起的组织”
。
我想检查我的索引是否位于 research
的 R
处。我可以使用 charAt(index) ,但我想使其通用,因为这将是识别首字母缩略词长形式的更大算法的一部分。所以本质上我想确定单词边界。
对此的帮助将不胜感激。
最佳答案
我还没有得到你问题的第二部分,“但我想让这个通用......,
public class IndexVal {
public static void main(String args[]){
String goodText="National Aeronautics Space Research is an amazing organization";
String[] parts = goodText.split(" ");
for (String part : parts) {
System.out.println("Index is at a word boundary " +part.charAt(0)+" ");
}
}
}
关于java - 识别字符串中单词的第一个字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40502179/