鉴于(至少在 NTFS 上)Windows 上的文件系统不区分大小写,我想将 String fileA
与 String fileB
进行比较:
fileA.Equals(fileB, StringComparison.CurrentCultureIgnoreCase)
然后问题就变成了我应该使用哪种文化,默认的当前(ui?)文化是否足够?我似乎找不到任何用于此目的的 BCL 方法。
最佳答案
根据 Best Practices for Using Strings in the .NET Framework,您应该使用 StringComparison.OrdinalIgnoreCase
.
The string behavior of the file system, registry keys and values, and environment variables is best represented by StringComparison.OrdinalIgnoreCase.
如果您使用区域性来匹配字符串,您可能会遇到这样一种情况,例如名称“häl.gif”和“hal.gif”将被视为匹配。
关于c# - .NET 如何比较两个代表文件名的字符串正确忽略大小写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1756724/