java中String.indexOf,用法  

查找指定字符或字符串在字符串中第一次出现地方的索引,未找到的情况返回 -1.

例如

String.indexOf(String str)

String str1="012345";
String str2="23";
System.out.println( str1.indexOf(str2) );

输出结果:2。

重载方法有

String.indexOf(String str,int index)

从index的地方开始找,返回第一次出现的索引

String str1="012345012345";
String str2="23";
System.out.println( str1.indexOf(str2,5) );

输出结果:8.

PS:转自:http://www.cnblogs.com/xumz/p/9293434.html

查找指定字符或字符串在字符串中第一次出现地方的索引,未找到的情况返回 -1.

例如

String.indexOf(String str)

String str1="012345";
String str2="23";
System.out.println( str1.indexOf(str2) );

输出结果:2。

重载方法有

String.indexOf(String str,int index)

从index的地方开始找,返回第一次出现的索引

String str1="012345012345";
String str2="23";
System.out.println( str1.indexOf(str2,5) );

输出结果:8.

PS:转自:http://www.cnblogs.com/xumz/p/9293434.html