Helps to compare strings, uses case insensitive comparison. - CSharp System

CSharp examples for System:String Case

Description

Helps to compare strings, uses case insensitive comparison.

Demo Code


using System.Text;
using System.Globalization;
using System.Collections.Specialized;
using System.Collections;
using System;/*from  www  . j av a 2 s  .  c  o m*/

public class Main{
        /// <summary>
        /// Helps to compare strings, uses case insensitive comparison.
        /// This overload allows multiple strings to be checked, if any of
        /// them matches we are good to go (e.g. ("hi", {"hey", "hello", "hi"})
        /// will return true).
        /// </summary>
        static public bool Compare( string s1, string[] anyMatch )
        {
            if ( anyMatch == null )
                throw new ArgumentNullException( "anyMatch",
                    "Unable to execute method without valid anyMatch array." );

            foreach ( string match in anyMatch )
                if ( String.Compare( s1, match, true,
                    CultureInfo.CurrentCulture ) == 0 )
                    return true;
            return false;
        } // Compare(s1, anyMatch)
        /// <summary>
        /// Helps to compare strings, uses case insensitive comparison.
        /// </summary>
        static public bool Compare( string s1, string s2 )
        {
            return String.Compare( s1, s2, true,
                CultureInfo.CurrentCulture ) == 0;
        } // Compare(s1, s2)
}

Related Tutorials