package com.zuidaima.util.string;
import java.io.*;
public class CountString {
public static int count(String result, String target) {
int count = 0;
int index = 0;
while (true) {
index = result.indexOf(target, index + 1);
if (index > 0) {
count++;
} else {
break;
}
}
br.close();
return count;
}
public static void main(String[] args) {
try {
System.out.println(count("asdajklsdjklasjdkalsj", "a"));
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
温馨提示:答案为网友推荐,仅供参考