我需要理解为什么字符串。StartsWith()在应该为假的时候是真的 [英] Need understanding as to why string.StartsWith() is true when it should be false
本文介绍了我需要理解为什么字符串。StartsWith()在应该为假的时候是真的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
u001a
开头。
这就是我被难住的地方,因为.StartsWith("u001a")
总是true
,但我不明白为什么。如果我在记事本++或十六进制编辑器中查看文件,我就看不到这一点。
所以我在这里遗漏了一些东西。
这里有一个最小的示例(fiddle):
// prints True in .NET 5
Console.WriteLine("Hello".StartsWith("u001a"));
推荐答案
是因为breaking change in the globalizations APIs in .NET 5。您可以选择以下方法之一
- 使用
StringComparison.Ordinal
或OrdinalIgnoreCase
- 使用NLS代替ICU,with one of the following ways:
- 在项目文件中:
<ItemGroup>
<RuntimeHostConfigurationOption Include="System.Globalization.UseNls" Value="true" />
</ItemGroup>
- 在runtimeconfig.json文件中:
{
"runtimeOptions": {
"configProperties": {
"System.Globalization.UseNls": true
}
}
}
- 将环境变量
DOTNET_SYSTEM_GLOBALIZATION_USENLS
设置为true
或1
。
这篇关于我需要理解为什么字符串。StartsWith()在应该为假的时候是真的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文