I wrote this a while ago on my old blog, so I'm just reposting here. It's useful since you can have an enum of error codes, which also, when converted to human readable text, are useful messages.
Here's how I did it.
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
public static string ToHumanFromPascal(this string s) | |
{ | |
if (2 > s.Length) | |
{ | |
return s; | |
} | |
var sb = new StringBuilder(); | |
var ca = s.ToCharArray(); | |
sb.Append(ca[0]); | |
for (int i = 1; i < ca.Length - 1; i++) | |
{ | |
char c = ca[i]; | |
if (char.IsUpper(c) && (char.IsLower(ca[i + 1]) || char.IsLower(ca[i - 1]))) | |
{ | |
sb.Append(' '); | |
} | |
sb.Append(c); | |
} | |
sb.Append(ca[ca.Length - 1]); | |
return sb.ToString(); | |
} |