Think about it this way: LastIndexOf
is kind of meaningless with an empty string. You could say the empty string exists at every index within a string, between each character. The documentation thus provides a definitive answer for what should be returned:
If value is String.Empty, the return
value is the last index position in
this instance.
At least in this case it returns an actual index. If it returned the string's length (representing the index "after" the end, which I believe was your point) it would be returning a result for a method called LastIndexOf
that isn't even an index.
And here's another way of looking at it: If I have this:
Dim index As Integer = str.LastIndexOf("")
...then I should be able to do this:
Dim substr As String = str.Substring(index, "".Length)
...and get ""
back. Sure enough, when LastIndexOf
returns the last index in the string, it works. If it returned the string's length, I'd get an ArgumentOutOfRangeException
. Edit: Well, looks like I was wrong there. Hopefully my first point was strong enough on its own ;)