Closed mkb137 closed 3 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: @tarekgh, @safern See info in area-owners.md if you want to be subscribed.
Author: | mkb137 |
---|---|
Assignees: | - |
Labels: | `area-System.Globalization`, `untriaged` |
Milestone: | - |
@mkb137 you are calling String.StartsWith
and not passing any StringComparison
option to the call. That means you are requesting the operation to be done linguistically (i.e. cultural aware). When doing the operation linguistically, the \0
is ignorable character. think about it as if it is not existing in the string at all. You may look at the Unicode standard https://www.unicode.org/charts/collation/chart_Ignored.html to see that the null is ignorable character when you compare.
To get your desired behavior, you need to do it as "x".StartsWith("\0", StringComparison.Ordinal)
which will make the operation performed in nonlinguistic way.
In .NET 5.0 we have switched to use ICU library for globalization which work according to Unicode Standard. That is why you are seeing a difference between .NET 3.x and 5.x. But if run on 3.x on Linux, you should see the exact same behavior as you see it in .NET 5.0. On Linux we have been using ICU since .NET Core 1.0 and that behavior is there since then.
Last, if you are using .NET 5.0 and running on Windows and want to switch back to older behavior (as what you used to get in 3.x), please follow the instructions in the doc https://docs.microsoft.com/en-us/dotnet/standard/globalization-localization/globalization-icu#use-nls-instead-of-icu. This doc is useful in general to read.
I am closing the issue but feel free to send any question you think we can help with. Thanks for your report.
Description
Expected:
Actual:
e.g.:
Also with multiples of null: e.g.:
Configuration
Basic console app, .net 5.0.
Problem doesn't exist on .netstandard3.0.
Regression?
Code:
.net 5.0:
output:
.net 3.1:
output:
Other information