Created
November 9, 2012 10:56
-
-
Save leekelleher/4045132 to your computer and use it in GitHub Desktop.
SpaceOutCamelCase - Method to space out a string on capitals or numbers.
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
/// <summary> | |
/// Spaces out a string on capitals or numbers. | |
/// </summary> | |
/// <param name="input">The input string.</param> | |
/// <returns> | |
/// The string with spaces before each capital letter or number | |
/// </returns> | |
public static string SpaceOutCamelCase(string input) | |
{ | |
var space = ' '; | |
var sb = new StringBuilder(); | |
for (var i = 0; i < input.Length; i++) | |
{ | |
if (i > 0 && (char.IsUpper(input, i) || char.IsNumber(input, i))) | |
{ | |
sb.Append(space); | |
} | |
sb.Append(input[i]); | |
} | |
return sb.ToString(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment