Created
January 16, 2013 17:50
-
-
Save DTTerastar/4549181 to your computer and use it in GitHub Desktop.
Turn Pascal cased Enums and Strings into more readable text by adding spaces
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
static public string ToStringAddSpaces(this Enum value) | |
{ | |
string a = value.ToString(); | |
return PascalCaseAddSpaces(a); | |
} | |
static public string[] PascalCaseToWords(string value) | |
{ | |
return Regex.Split(value, "(?<!(^|[A-Z]))(?=[A-Z])|(?<!^)(?=[A-Z][a-z])"); | |
} | |
static public string PascalCaseAddSpaces(string value) | |
{ | |
return string.Join(" ", PascalCaseToWords(value)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment