Skip to content

Instantly share code, notes, and snippets.

@gabrieljoelc
Created November 8, 2013 17:08
Show Gist options
  • Save gabrieljoelc/7374242 to your computer and use it in GitHub Desktop.
Save gabrieljoelc/7374242 to your computer and use it in GitHub Desktop.
public static class StringExtensions
{
public static string ToStringWithSpaces(this string input)
{
return Regex.Replace(
input,
"(?<!^)" + // don't match on the first character - never want to place a space here
"(" +
" [A-Z][a-z] |" + // put a space before "Aaaa"
" (?<=[a-z])[A-Z] |" + // put a space into "aAAA" before the first capital
" (?<![A-Z])[A-Z]$" + // if the last letter is capital, prefix it with a space too
")",
" $1",
RegexOptions.IgnorePatternWhitespace);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment