I have two strings "CZSczs
" - "ČŽŠčžš
" and I want to return true when I compare the strings. I tried with string comparison but it doesn't work.
我有两个字符串“CZSczs” - “ČŽŠčžš”,我想在比较字符串时返回true。我尝试使用字符串比较,但它不起作用。
2 个解决方案
#1
You can use
您可以使用
int result string.Compare("CZSczs", "ČŽŠčžš", CultureInfo.InvariantCulture, CompareOptions.IgnoreNonSpace);
bool equal = result == 0;
As pointed out in this question's accepted answer.
正如这个问题所指出的那样。
#2
You need to specify the culture :
您需要指定文化:
using System;
public class Program
{
public static void Main()
{
string string1 = "CZSczs";
string string2 = "ČŽŠčžš";
if(String.Compare(string1, string2, CultureInfo.CurrentCulture, CompareOptions.IgnoreNonSpace) == 0)
{
Console.WriteLine("same");
}
else
{
Console.WriteLine("not same");
}
}
}
See this working code on : DotNetFiddle
请参阅以下工作代码:DotNetFiddle
#1
You can use
您可以使用
int result string.Compare("CZSczs", "ČŽŠčžš", CultureInfo.InvariantCulture, CompareOptions.IgnoreNonSpace);
bool equal = result == 0;
As pointed out in this question's accepted answer.
正如这个问题所指出的那样。
#2
You need to specify the culture :
您需要指定文化:
using System;
public class Program
{
public static void Main()
{
string string1 = "CZSczs";
string string2 = "ČŽŠčžš";
if(String.Compare(string1, string2, CultureInfo.CurrentCulture, CompareOptions.IgnoreNonSpace) == 0)
{
Console.WriteLine("same");
}
else
{
Console.WriteLine("not same");
}
}
}
See this working code on : DotNetFiddle
请参阅以下工作代码:DotNetFiddle