does anyone know why:
" <exception>".LastIndexOf("<",0) returns -1 (wrong)
while
" <exception>".LastIndexOf("<") returns 2 (right)
and
"<exception>".LastIndexOf("<",0) returns 0 (right)
Is this a bug or am I misunderstanding the LastIndexOf-Method?
You are misunderstanding that particular overload of the
LastIndexOfmethod.The docs state the following:
Note that it says
backward. So, if you start at position0, there is no"<"substring at that position or in front of that position and hence the result is-1.In contrast, if you use the overload that takes only the substring, the search will start at the end of the string and hence correctly find the indicated substring.