Last active
August 29, 2015 14:05
-
-
Save mcgwiz/c81c641c4d6d3b232371 to your computer and use it in GitHub Desktop.
ToTitleCaseFromPascal
This file contains hidden or 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
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