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 5,325 times
        
    6
            
            
         
    
    
        shA.t
        
- 16,580
- 5
- 54
- 111
 
    
    
        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
        
- 450,073
- 74
- 686
- 939
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,204
- 10
- 65
- 133