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.
Asked
Active
Viewed 4,657 times
6
shA.t
- 15,880
- 5
- 49
- 104
Riddhi Vadukiya
- 61
- 1
- 2
2 Answers
3
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.
Community
- 1
- 1
Tim Schmelter
- 429,027
- 67
- 649
- 891
0
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
clement
- 4,330
- 10
- 61
- 132