Created
July 7, 2012 10:33
-
-
Save timiles/3065794 to your computer and use it in GitHub Desktop.
ToUnderscoreCase / ToHyphenCase
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Converts PascalCase and camelCase to underscore_case. Leaves underscore_case unaffected. | |
/// </summary> | |
/// <param name="s">the string to convert</param> | |
/// <returns>the underscore_cased string</returns> | |
internal static string ToUnderscoreCase(this string s) | |
{ | |
return Regex.Replace(s, @"(\p{Ll})(\p{Lu})", "$1_$2").ToLower(); | |
} | |
/// <summary> | |
/// Converts PascalCase and camelCase to hyphen-case. Leaves hyphen-case unaffected. | |
/// </summary> | |
/// <param name="s">the string to convert</param> | |
/// <returns>the hyphen-cased string</returns> | |
internal static string ToHyphenCase(this string s) | |
{ | |
return Regex.Replace(s, @"(\p{Ll})(\p{Lu})", "$1-$2").ToLower(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment