C#中的文件路径字符串比较不区分大小写 [英] c# file path string comparison case insensitivity

查看:1510
本文介绍了C#中的文件路径字符串比较不区分大小写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想比较包含在C#中的文件路径两个字符串。

I would like to compare two strings containing file paths in c#.

然而,由于在NTFS默认是使用不区分大小写的路径,我想串比较区分以同样的方式不敏感。

However, since in ntfs the default is to use case insensitive paths, I would like the string comparison to be case insensitive in the same way.

不过,我似乎无法找到在NTFS如何真正实现其不区分大小写的任何信息。我想知道的是如何执行使用NTFS使用的文件路径相同的外壳规则的字符串区分大小写的比较。

However I can't seem to find any information on how ntfs actually implements its case insensitivity. What I would like to know is how to perform a case insensitive comparison of strings using the same casing rules that ntfs uses for file paths.

推荐答案

文件系统的字符串行为,注册表项和值以及环境变量是最好的 StringComparison.OrdinalIgnoreCase 表示。

The string behavior of the file system, registry keys and values, and environment variables is best represented by StringComparison.OrdinalIgnoreCase.

在解释文件名,Cookie或任何其他地方的组合,如A可以出现,依次比较仍然提供了最透明,最恰当的行为。

When interpreting file names, cookies, or anything else where a combination such as "å" can appear, ordinal comparisons still offer the most transparent and fitting behavior.

因此它只是

String.Equals(fileNameA, fileNameB, StringComparison.OrdinalIgnoreCase)

(我一直使用静态等于万一调用左操作数

(I always use the static Equals call in case the left operand is null)

这篇关于C#中的文件路径字符串比较不区分大小写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆