Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何比较C#中的亚洲(越南语/unicode)字符串?_C# - Fatal编程技术网

如何比较C#中的亚洲(越南语/unicode)字符串?

如何比较C#中的亚洲(越南语/unicode)字符串?,c#,C#,我有以下代码: Thread.CurrentThread.CurrentCulture = new CultureInfo("vi-VN"); string a = "Biển Ðông"; string b = "Biển Đông"; if (a.Equals(b, StringComparison.CurrentCulture)) { Console.WriteLine("Yes"); } 这两个字符串是相同的,但是当使用Equals进行检查时,我总是得到false。如果我将

我有以下代码:

Thread.CurrentThread.CurrentCulture = new CultureInfo("vi-VN");

string a = "Biển Ðông";
string b = "Biển Đông";

if (a.Equals(b, StringComparison.CurrentCulture))
{
    Console.WriteLine("Yes");
}

这两个字符串是相同的,但是当使用
Equals
进行检查时,我总是得到
false
。如果我将此项添加到
散列集,则容器中会有两项而不是一项。

Ð
在您的情况下不是
Đ

第一个“D”是ANSI字符208,第二个是272

我使用

(int)'Ð'
(int)'Đ'

这些是看起来相同但不相同的不同字符。

您的字符串由以下字符组成:

\u0042\u0069\u1ec3\u006e \u00d0\u00f4\u006e\u0067
                            |||
\u0042\u0069\u1ec3\u006e \u0110\u00f4\u006e\u0067

通过这种逻辑,您可以找到字符串中的第一个字符是不同的。在这种情况下,它可能很有用

char? firstocurrenceA = string1.Zip(string2, (a, b) => new { string1 = a, string2 = b })
    .Where(x => x.string1 != x.string2)
    .Select(x => x.string1)
    .FirstOrDefault();

        char? firstocurrenceB = string1.Zip(string2, (a, b) => new { string1 = a, string2 = b })
    .Where(x => x.string1 != x.string2)
    .Select(x => x.string2)
    .FirstOrDefault();

它们在javascript中甚至不匹配-一定有不同之处。在样本B中似乎有一个不可打印的字符。它们在PHPDamn中也不匹配,30秒显示。做得好!泰克斯兄弟。太快了,不客气。另外,请查看LINQPad。我使用这个工具进行诊断。如果输入这两行中的任何一行,将对表达式求值,以便查看它是哪个字符,而无需创建解决方案来执行小代码段。