Thursday, 22 April 2010

Regular expression for PascalCased enums into words.

Ever used an enum to reference values that come out of the database? Of course you have, now you can use this regular expression that I syumbled for turning pascal cased strings (i.e. Enum values) to a string with the necessary spaces in - i.e. MyEnumValue comes out as "My Enum Value".

System.Text.RegularExpressions.Regex.Replace(text, "[A-Z]", " $0").Trim();

No comments: