Created
February 1, 2012 15:49
-
-
Save benjaminramey/1717658 to your computer and use it in GitHub Desktop.
This little method (in C#) splits a pascal-cased string along the word boundaries to put spaces between the words. A pascal-cased string is a string where each word boundary begins with a capital letter.
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
| public static string SpacePascalCase(string input) | |
| { | |
| string splitString = String.Empty; | |
| for (int idx = 0; idx < input.Length; idx++) | |
| { | |
| char c = input[idx]; | |
| if (Char.IsUpper(c) | |
| // keeps abbreviations together like "Number HEI" | |
| // instead of making it "Number H E I" | |
| && ((idx < input.Length - 1 | |
| && !Char.IsUpper(input[idx + 1])) | |
| || (idx != 0 | |
| && !Char.IsUpper(input[idx - 1]))) | |
| && splitString.Length > 0) | |
| { | |
| splitString += " "; | |
| } | |
| splitString += c; | |
| } | |
| return splitString; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment