Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
ToTitleCaseFromPascal
static string ToTitleFromPascalCase(string s) {
var sb = new StringBuilder();
for (var i = 0; i < s.Length; i++) {
var c = s[i];
if (c == ' ') { continue; }
if (i == 0) { sb.Append(c); continue; }
if (!char.IsUpper(c)) { sb.Append(c); continue; }
if (!char.IsUpper(s[i - 1])) { sb.Append(' ').Append(c); continue; }
var ii = i + 1;
if (ii < s.Length && !char.IsUpper(s[ii])) { sb.Append(' ').Append(c); continue; }
sb.Append(c);
}
return sb.ToString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment