-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
String.StartsWith doesn't work if the string contains "AA" when using Norwegian/Danish cultureinfo in .NET 6 #73999
Comments
Tagging subscribers to this area: @dotnet/area-system-globalization Issue DetailsDescriptionString.StartsWith() will sometimes return the wrong value if the string contains "AA" and culture is set to Norwegian (nb-NO) or Danish (da-DK) Even though the double A has a special meaning in Norwegian, I would expect Example .net fiddle: Reproduction Steps
Expected behaviorb should be true Actual behaviorb is false Regression?Using .NET 4.7.2, it works as expected for Norwegian, returning true. But for Danish it is still false. Example: Known WorkaroundsSpecifying InvariantCulture fixes the problem. ConfigurationNo response Other informationNo response
|
FWIW I don't know specifics of Danish/Norwegian culture but in Polish we also have special phonetic characters (i.e. string test = "Pszczoła";
Console.WriteLine(test.StartsWith(test.Substring(0, 2), false, CultureInfo.CreateSpecificCulture("pl-PL"))); // true ever returned false (this works as I'd expect for Polish) so it makes sense that this works consistently across other cultures as well. |
@runebrg this behavior is defined by the Unicode standard. If you disagree with this behavior, you may log a ticket to ICU unicode-org.atlassian.net/jira/software/c/projects/ICU/issues. |
I agree that Fiddle: |
It does, but this behavior is documented and I believe it can't be changed, because that would break backwards compatibility. |
The following operations are performed as ordinal operation and not linguistic operation. You can achieve the same things with StartsWith and input string by doing something like Console.WriteLine("aa".Contains("a")); //True
Console.WriteLine("aa".StartsWith('a')); //True Also, consistency with .NET Framework can be achieved if you enable the NLS mode. We don't recommend that though. |
Description
String.StartsWith() will sometimes return the wrong value if the string contains "AA" and culture is set to Norwegian (nb-NO) or Danish (da-DK)
Even though the double A has a special meaning in Norwegian, I would expect
s.StartsWith(s.Substring(0, 2))
to always return trueExample .net fiddle:
https://dotnetfiddle.net/h4u01x
Reproduction Steps
var s = "BAAC"; var b = s.StartsWith(s.Substring(0, 2), false, CultureInfo.CreateSpecificCulture("nb-NO"));
Expected behavior
b should be true
Actual behavior
b is false
Regression?
Using .NET 4.7.2, it works as expected for Norwegian, returning true. But for Danish it is still false.
Example:
https://dotnetfiddle.net/FCwqGH
Known Workarounds
Specifying InvariantCulture fixes the problem.
Configuration
No response
Other information
No response
The text was updated successfully, but these errors were encountered: