I have this code:
string Str = "<String><MoreString>";
int Start = Str.LastIndexOf('<') + 1;
int End = Str.IndexOf('>', Start);
string S = Str.Substring(Start, End);
If Str is just "<String>", then it works fine, but if Str is "<String><MoreString>", then it throws an index out of range error. Is it because of the “<“,”>” characters?
Substring doesn’t work like this.
Example :
The second argument is the number of characters you’re going to select, so you should do :