Skip to content

Instantly share code, notes, and snippets.

@leekelleher
Created November 9, 2012 10:56
Show Gist options
  • Save leekelleher/4045132 to your computer and use it in GitHub Desktop.
Save leekelleher/4045132 to your computer and use it in GitHub Desktop.
SpaceOutCamelCase - Method to space out a string on capitals or numbers.
/// <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