|
public class RegionMatchesDemo {
public static void main(String[] args) {
String searchMe = "Green Eggs and Ham";
String findMe = "Eggs";
int len = findMe.length();
boolean foundIt = false;
int i = 0;
while (!searchMe.regionMatches(i, findMe, 0, len)) {
i++;
foundIt = true;
}
if (foundIt) {
System.out.println(searchMe.substring(i, i+len));
}
}
}
主要还是关于searchMe.regionMatches()这个方法的问题。大家看此程序是否有错吧,运行结果是正确的,但总是感觉有些不对劲。 |
|