How do I find the second index of a character in a string. For instance:
String a="aa{aaaaaaa{aaa}";
I'd like to find the index value of the second {
. Here it is 10.
Find the first one, move one right, then find the next one from there. That's the second :)
int secondIndex = a.indexOf('{', a.indexOf('{')+1);
尝试重载版本的indexOf()
,它将起始索引作为第二个参数。
str.indexOf("{", str.indexOf("}") + 1);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.