Friday, December 11, 2009

Show enum with space {If you are using Pascal case for Data}.

Hi All,

for a long period i was looking for some solution to allowing space in Enum to show Friendly while Displaying.

after digging too much i have come up with solution. I was using Pascal casing for strings shown in Enum, so here i have done some logic,

static string ToFriendlyCase(this string EnumString)
{
return Regex.Replace(EnumString, "(?!^)([A-Z])", " $1");
}

so if you Enum is TextField it will show you as "Text Field".

Happy Coding :-)

No comments:

Post a Comment