Skip to content

Instantly share code, notes, and snippets.

@Krummelz
Created September 12, 2013 07:26
Show Gist options
  • Save Krummelz/6533983 to your computer and use it in GitHub Desktop.
Save Krummelz/6533983 to your computer and use it in GitHub Desktop.
Useful C# Extension Methods
/// <summary>
/// This will return a camel-cased string, so that it reads as a normal string, by adding a space before each capital letter.
/// </summary>
public static string SpaceOutCamelCasing(this string theWord)
{
char[] temp = theWord.ToCharArray();
string Result = "";
foreach (char c in temp)
if (c.ToString() == c.ToString().ToUpper())
Result += " " + c;
else
Result += c;
return Result;
}
@MTariqAziz
Copy link

One liner:

String.Concat(Regex.Split("myCamelCaseString", "(?=[A-Z])").Select(x => x + " "));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment