Wordify: .NET/C# – Convert enums to human readable values – Stack Overflow
Posted by jpluimers on 2013/01/03
You’d hope that a method like Wordify with the signature below would be simple right?
public static string Wordify(string pascalCaseString)
Not so.
It uses some RegEx, and I wonder who’d be able to maintain these things: I can’t even assess if this is clever or not so clever RegEx.
/// <summary>
/// Add spaces to separate the capitalized words in the string,
/// i.e. insert a space before each uppercase letter that is
/// either preceded by a lowercase letter or followed by a
/// lowercase letter (but not for the first char in string).
/// This keeps groups of uppercase letters - e.g. acronyms - together.
/// </summary>
/// <param name="pascalCaseString">A string in PascalCase</param>
/// <returns></returns>
public static string Wordify(string pascalCaseString)
{
Regex r = new Regex("(?<=[a-z])(?<x>[A-Z])|(?<=.)(?<x>[A-Z])(?=[a-z])");
return r.Replace(pascalCaseString, " ${x}");
}
–jeroen
via: c# – Convert enums to human readable values – Stack Overflow.






Paul Hilt said
I had my fun with some Java RegEx functions (Pattern and Matcher), even wrote a few myself after a while. The testcase for this function would be “IBMTextString” have to brush up on the C# RegEx function to see if this test passes or not.