So I have this file that I download via ftp. The file is just a config file for a system at my company I work for.
Once the file is downloaded I open the file and processor the file.
Part of the processing of the file is to check to see if a line starts with a Unicode character \u001a
.
This is where I am stumped because .StartsWith("\u001a")
is always true
, yet I cannot see why. If I view the file in Notepad++ or in a hex editor, I just don't see that.
So there is something I am missing here.
Here's a minimal example (fiddle):
// prints True in .NET 5
Console.WriteLine("Hello".StartsWith("\u001a"));
The startswith() method returns True if the string starts with the specified value, otherwise False.
JavaScript String startsWith() The startsWith() method returns true if a string starts with a specified string. Otherwise it returns false . The startsWith() method is case sensitive.
Python String startswith() method returns True if a string starts with the specified prefix(string). If not, it returns False.
In C#, StartsWith() is a string method. This method is used to check whether the beginning of the current string instance matches with a specified string or not. If it matches then it returns the string otherwise false.
It's because a breaking change in the globalizations APIs in .NET 5. You can choose one of the following approaches
StringComparison.Ordinal
or OrdinalIgnoreCase
<ItemGroup>
<RuntimeHostConfigurationOption Include="System.Globalization.UseNls" Value="true" />
</ItemGroup>
{
"runtimeOptions": {
"configProperties": {
"System.Globalization.UseNls": true
}
}
}
DOTNET_SYSTEM_GLOBALIZATION_USENLS
to the value true
or 1
.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With