在这个例子中,我无法计算给定字符串中的“manoj”......我怎么能做到这一点..
String text = "manoj kumjjjartiwarimanojmanoj";
char[] line = text.toCharArray();
char[] temp = "manoj".toCharArray();
int count=0;
for (int i =0; i < line.length; i++) {
int t =0;
for (int j = 0; j < temp.length; j++) {
if(line[i]==temp[j]){
t=1;
}
else{
t=0;
}
}
if(t==1){
count=count+1;
}
}
System.out.println(count);
可以用各种方法完成,你真的应该在问之前在谷歌上搜索这个,但我提供了一个代码
String text = "manoj kumjjjartiwarimanojmanoj";
Pattern p = Pattern.compile("manoj");
Matcher m = p.matcher(text);
int count = 0;
while (m.find())
{
count +=1;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句