package chap05;
public class StringFindTest {
public static void testFind(String str, String substr) {
int count = 0;
int pos = 0;
do{
if(str.indexOf(substr, pos) >= 0){
countPP;
System.out.println(""+count+":"+str.indexOf(substr, pos));
pos = str.indexOf(substr, pos) + substr.length() - 1;
}
}while(pos >= 0);
}
public static void main(String[] args) {
//StringFindTest test = new StringFindTest();
String str = "AAA01234AA01234aa012340aAA01234Aa01234aa";
String substr = "AA";
//
testFind(str.toUpperCase(), substr.toUpperCase());
//
testFind(str, substr);
}
}
< H2 > run results < / H2 > The first occurrence position of the substring is: the second occurrence position of the 0
substring is: 1 the third occurrence position of the
substring is: the fourth occurrence position of the 8
substring is: the 5th occurrence position of the 15
substring is: 23
the 6th occurrence position of the substring is: 24
the 7th occurrence position of the substring is: 31
the 8th occurrence position of the substring is: 38
as above, why?