第1个回答 2010-07-27
import java.io.*;
public class StringMatch {
public static void main(String args[]) {
int count = 0;
try {
FileReader in = new FileReader("C:/test.txt");
BufferedReader br = new BufferedReader(in);
String str = br.readLine();
// System.out.println(str);
while (str != null) {
String sToFind = "mobnet";
int index = -1;
while (str.indexOf(sToFind) != -1) {
index = str.indexOf(sToFind) + sToFind.length();
str = str.substring(index);
count++;
}
str = br.readLine();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(count);
}
}
写得比较粗糙! 见谅!