is there a command that can get the third index of a character in a string? For example:
error: file.ext: line 10: invalid command [test:)]
In the above sentence, I want to the index of the 3rd colon, the one next to the 10. How could I do that? I know of string.IndexOf and string.LastIndexOf, but in this case I want to get the index of a character when it is used the third time.
String.IndexOfwill get you the index of the first, but has overloads giving a starting point. So you can use a the result of the firstIndexOfplus one as the starting point for the next. And then just accumulate indexes a sufficient number of times:Add error handling unless you know that
myStringcontains at least three colons.