[英]Identify last letter of each word
String str = "Ada apa dengannya axr"
int count = 0;
I want to identify if the last letter of each word is "a/r/n/z", if it's is one of the mentioned letter then count++
. 我想确定每个单词的最后一个字母是否为“ a / r / n / z”,如果它是所提到的字母之一,则为
count++
。 I don't understand regex or matches yet, so an explanation would be really helpful. 我尚不了解正则表达式或匹配项,因此进行解释将非常有帮助。 Thank you.
谢谢。
Regular Expression will find all occurrences in your input string of what is logically equivalent to the regex. 正则表达式将在输入字符串中查找在逻辑上等同于正则表达式的所有匹配项。
The comments to the question are saying to find all occurrences of "a" or "n" or "r" or "z" which are followed by the end of the word (\\b). 问题的注释是说要找到所有出现的“ a”或“ n”或“ r”或“ z”,其后是单词(\\ b)的结尾。
Another way to do it could be to use the split function in java. 另一种方法是在Java中使用split函数。
String[] words = str.split(" ");
for (String word : words) {
// if the last letter is what you are looking for, count++;
}
This is far less efficient, but it is much more clear what the computer is doing, which may help you learn more. 这样的效率要差得多,但是却可以清楚地知道计算机在做什么,这可能有助于您了解更多信息。
Good luck! 祝好运!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.