You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When we go to the IndexOf method, the following code returns 0, which is expected, as we saw that both string are equivalent under invariant culture and ignore case.
However, when we use any letters from the English alphabet or spaces at the beginning of the string, we starting to get -1. But if we use some other letters (Cyrillic, Arabic, Hebrew, Latin with umlauts), it gives proper result again. Example in the next section.
Description
We found a weird behavior in the
IndexOf
method of strings.The official Unicode specs regarding Special Casing claims that the upper case of the character
st
isST
.And as expected the following comparison, returns true.
When we go to the
IndexOf
method, the following code returns 0, which is expected, as we saw that both string are equivalent under invariant culture and ignore case.However, when we use any letters from the English alphabet or spaces at the beginning of the string, we starting to get -1. But if we use some other letters (Cyrillic, Arabic, Hebrew, Latin with umlauts), it gives proper result again. Example in the next section.
Reproduction Steps
Expected behavior
The expected behavior is that
IndexOf
will behave in the same way no matter the other characters in the string. So in the examples where we got -1We will get 1 and 3, respectively.
Actual behavior
The actual behavior is that
IndexOf
with InvariantCultureIgnoreCase is not constant and may return wrong output based on surrounding string content.Regression?
We get the observed results under .NET 5 and above. In .NET Framework 4.7.2 we get the expected results:
Known Workarounds
Turning of the usage of ICU can solve that issue, but this is unwanted workaround, since other part of the code uses the ICU logic.
Configuration
.NET 5, .NET 6, .NET 7, .NET 8
Windows 11
x64, x86
Other information
No response
The text was updated successfully, but these errors were encountered: