CSharp examples for System:String Case
Compare char case insensitive
using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.Collections.Specialized; using System.Collections; using System.Text; using System;/*from w w w . j a va2s.co m*/ public class Main{ /// <summary> /// Compare char case insensitive /// </summary> /// <param name="c1">C 1</param> /// <param name="c2">C 2</param> /// <returns>Bool</returns> public static bool CompareCharCaseInsensitive(char c1, char c2) { return char.ToLower(c1) == char.ToLower(c2); // Another way (slower): // return String.Compare("" + c1, "" + c2, true) == 0; } // CompareCharCaseInsensitive(c1, c2) /// <summary> /// Helper function to convert letter to lowercase. Could someone /// tell me the reason why there is no function for that in char? /// </summary> public static char ToLower(char letter) { return (char)letter.ToString().ToLower( CultureInfo.InvariantCulture)[0]; } // ToLower(letter) }