Use the Compare() method to compare strings : String : String C# Examples


C# Examples » String » String »

 

Use the Compare() method to compare strings









    
using  System;

class  MainClass
{

    public  static  void  Main()
    {
        
        int  result;
        result  =  String.Compare("bbc",  "abc");
        Console.WriteLine("String.Compare(\"bbc\",  \"abc\")  =  "  +  result);
        result  =  String.Compare("abc",  "bbc");
        Console.WriteLine("String.Compare(\"abc\",  \"bbc\")  =  "  +  result);
        result  =  String.Compare("bbc",  "bbc");
        Console.WriteLine("String.Compare(\"bbc\",  \"bbc\")  =  "  +  result);
        result  =  String.Compare("bbc",  "BBC",  true);
        Console.WriteLine("String.Compare(\"bbc\",  \"BBC\",  true)  =  "  +  result);
        result  =  String.Compare("bbc",  "BBC",  false);
        Console.WriteLine("String.Compare(\"bbc\",  \"BBC\",  false)  =  "  +  result);
        result  =  String.Compare("Hello  World",  6,  "Goodbye  World",  8,  5);
        Console.WriteLine("String.Compare(\"Hello  World\",  6,  "  +  "\"Goodbye  World\",  8,  5)  =  "  +  result);

    }

}
    
   
  
   



Output

String.Compare("bbc", "abc") = 1
String.Compare("abc", "bbc") = -1
String.Compare("bbc", "bbc") = 0
String.Compare("bbc", "BBC", true) = 0
String.Compare("bbc", "BBC", false) = -1
String.Compare("Hello World", 6, "Goodbye World", 8, 5) = 0


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo String
» String