Reputation: 4708
I have a large string, and a part of this string starts like this:
data-json="{"id":
and ends like this:
"}}}"
I am using the IndexOf method to find positions of data-json="
and the "
in the end of the string.
However, when trying to find the index of the "
, I get the index of the first "
instead (in the string in the top of the post).
How can I make the IndexOf method distinguish between "
and "
?
This is how I search for the "
:
string.IndexOf("\"", startIndex);
Of course maybe it could be possible to search for }}}"
instead, but now I'm curious how to make the IndexOf method behave like I want it to.
Upvotes: 0
Views: 315
Reputation: 4708
This is embarrassing, please forgive my rookie mistake:
The startIndex used in the IndexOf method was simply wrong (it found the "
in data-json="
because the startIndex value was too small).
Upvotes: 0
Reputation: 3361
You can always use LastIndexOf method. That is intended for this purpose. If you want the last quote then this method is for you.
For instance:
// Determine where last quote is.
int position = filepath.LastIndexOf('\"');
I am not sure if I understood your problem. So if this doesn't help or isn't related I apologize.
Upvotes: 1