Specifying a 'culture' in string comparison - CSharp Language Basics

CSharp examples for Language Basics:string

Description

Specifying a 'culture' in string comparison

Demo Code

using System;/*w  w w  .j a v a  2  s. c  o  m*/
using System.Text;                // Need for type UTF8Encoding.
using System.Globalization;       // Need for cultures.
class Program
{
   static void Main(string[] args)
   {
      string line = "SOME STUFF";
      if (string.Compare(line.ToUpper(CultureInfo.InvariantCulture), line, false) == 0)
         Console.WriteLine("yes 1");
      if (string.Compare(line, "line", StringComparison.InvariantCultureIgnoreCase) == 0)
         Console.WriteLine("yes 2");
      }
}

Result


Related Tutorials