Skip to content

Instantly share code, notes, and snippets.

@fresky
Created July 23, 2012 09:18
Show Gist options
  • Save fresky/3162758 to your computer and use it in GitHub Desktop.
Save fresky/3162758 to your computer and use it in GitHub Desktop.
c# StringComparison example
Console.WriteLine("CurrentCulture: " + StringComparison.CurrentCulture);
Console.WriteLine("InvariantCulture: " + StringComparison.InvariantCulture);
Console.WriteLine("Ordinal: " + StringComparison.Ordinal);
Console.WriteLine();
const string softhyphen = "\xAD";
const string hyphen = "\x2D";
const string softHyphenPlusHyphen = "\xAD\x2D";
const string hyphenPlusSoftHyphen = "\x2D\xAD";
Console.WriteLine("softhyphen: " + softhyphen);
Console.WriteLine("hyphen: " + hyphen);
Console.WriteLine("softHyphenPlusHyphen: " + softHyphenPlusHyphen);
Console.WriteLine("hyphenPlusSoftHyphen: " + hyphenPlusSoftHyphen);
Console.WriteLine();
Console.WriteLine("softHyphenPlusHyphen.IndexOf(softHyphenPlusHyphen, StringComparison.Ordinal): " + softHyphenPlusHyphen.IndexOf(softHyphenPlusHyphen, StringComparison.Ordinal));
Console.WriteLine("softHyphenPlusHyphen.IndexOf(softHyphenPlusHyphen): " + softHyphenPlusHyphen.IndexOf(softHyphenPlusHyphen));
Console.WriteLine("softHyphenPlusHyphen.IndexOf(softHyphenPlusHyphen, CurrentCulture): " + softHyphenPlusHyphen.IndexOf(softHyphenPlusHyphen, StringComparison.CurrentCulture));
Console.WriteLine("softHyphenPlusHyphen.IndexOf(softHyphenPlusHyphen, InvariantCulture): " + softHyphenPlusHyphen.IndexOf(softHyphenPlusHyphen, StringComparison.InvariantCulture));
Console.WriteLine();
Console.WriteLine("hyphenPlusSoftHyphen.IndexOf(hyphenPlusSoftHyphen, StringComparison.Ordinal): " + hyphenPlusSoftHyphen.IndexOf(hyphenPlusSoftHyphen, StringComparison.Ordinal));
Console.WriteLine("hyphenPlusSoftHyphen.IndexOf(hyphenPlusSoftHyphen): " + hyphenPlusSoftHyphen.IndexOf(hyphenPlusSoftHyphen));
Console.WriteLine();
Console.WriteLine("softHyphenPlusHyphen.IndexOf(softhyphen, StringComparison.Ordinal): " + softHyphenPlusHyphen.IndexOf(softhyphen, StringComparison.Ordinal));
Console.WriteLine("softHyphenPlusHyphen.IndexOf(softhyphen): " + softHyphenPlusHyphen.IndexOf(softhyphen));
Console.WriteLine("softHyphenPlusHyphen.IndexOf(hyphen): " + softHyphenPlusHyphen.IndexOf(hyphen));
Console.WriteLine();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment