gpt4 book ai didi

c# - .NET 如何比较两个代表文件名的字符串正确忽略大小写

转载 作者:可可西里 更新时间:2023-11-01 02:59:01 24 4
gpt4 key购买 nike

鉴于(至少在 NTFS 上)Windows 上的文件系统不区分大小写,我想将 String fileAString 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com