我想确定我的索引是否在单词边界处。识别字符串中单词的第一个字符
E.g.在字符串"National Aeronautics Space Research is an amazing organization"
。
我想检查我的指数是在research
R
。我可以使用一个charAt(index)
,但我想使这个通用,因为这将是一个更大的算法识别首字母缩写词的一部分。所以基本上我想确定词的边界。
帮助这将不胜感激。
我想确定我的索引是否在单词边界处。识别字符串中单词的第一个字符
E.g.在字符串"National Aeronautics Space Research is an amazing organization"
。
我想检查我的指数是在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)+" ");
}
}
}
据我了解,你想获得字边界的索引。然后,它使用正则表达式
Pattern pattern = Pattern.compile("\\s\\w");
String s = "National Aeronautics Space Research is an amazing organization";
Matcher matcher = pattern.matcher(s);
while (matcher.find()) {
System.out.println(matcher.start());
}
如果index大于0,那么你可以检查index-1的值?识别单词界限*?你能解释一下你想要做什么吗? – TheLostMind
请注意,这不是一个免费的代码 - wri我们非常乐意帮助其他程序员(和有志之士)编写他们自己的代码。请阅读[如何提出问题](http://stackoverflow.com/help/how-to-ask)上的帮助主题。之后,请用您迄今编写的代码更新您的问题,以完成您希望实现的任务。 –