Reputation: 407
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.
Upvotes: 4
Views: 14028
Reputation: 561
Try to overloaded version of indexOf()
, which takes the starting index as 2nd parameter.
str.indexOf("{", str.indexOf("{") + 1);
Upvotes: 4
Reputation: 15758
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);
Upvotes: 10