返回指定字符在字符串中第一次出现处的索引(int),没找到则返回 -1
参数有 String 类型和 int 类型,共4种
String string = “aaa456ac”;
string.indexOf(“b”) //indexOf(String str); 返回结果:-1,"b"不存在
string.indexOf(“a”,3) //indexOf(String str, int fromIndex); 从第四个字符位置开始往后继续查找,包含当前位置;返回结果:6
//a-97,b-98,c-99
string.indexOf(99) //indexOf(int ch);返回结果:7
string.indexOf(‘c’) //indexOf(int ch);返回结果:7
string.indexOf(97,3) //indexOf(int ch, int fromIndex); 返回结果:6
string.indexOf(‘a’,3) //indexOf(int ch, int fromIndex); 返回结果:6