Open CaiusJard opened 2 years ago
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.
Tagging subscribers to this area: @dotnet/area-system-globalization See info in area-owners.md if you want to be subscribed.
Author: | CaiusJard |
---|---|
Assignees: | - |
Labels: | `Pri3`, `area-System.Globalization` |
Milestone: | - |
@CaiusJard are you interested to submit a PR to fix this? you may tag me in that PR. Thanks!
If we call
"abcabcabc".LastIndexOf("abc", 4)
we might reasonably expect it to return 3, having assessed the character at start index 4 to be 'b' and thus not equal to 'a' of the needle, and moved one position towards the start, where we can find 'a', 'b' and 'c' in indexes 3, 4 and 5 respectivelyLastIndexOf actually returns 0, indicating the first match found is the "abc" at the start of the string. A comment in the source code explains the behavior, namely that LastIndexOf() overloads taking a startIndex do not consider characters to the right of the character at startIndex (so for a startIndex of 4, the trailing characters "cabc" are not searched/do not contribute towards finding a match; the search is executed as if the haystack is a Substring terminating after the startIndex character I.e. "abcab")
The current wording of the documentation only states where searching begins and states the direction but I believe it would benefit from an addition that explains the scope of the search doesn't extend to looking for characters to the right of startIndex