Skip to content

Instantly share code, notes, and snippets.

@smartmeter
Forked from vkobel/underscoreCase.cs
Created August 12, 2016 19:04
Show Gist options
  • Save smartmeter/9e9b631fdbde42e547119a9fc2e6ea2f to your computer and use it in GitHub Desktop.
Save smartmeter/9e9b631fdbde42e547119a9fc2e6ea2f to your computer and use it in GitHub Desktop.
Simple C# extension method to convert a camel case string to underscore notation without any regex
public static class ExtensionMethods {
public static string ToUnderscoreCase(this string str) {
return string.Concat(str.Select((x, i) => i > 0 && char.IsUpper(x) ? "_" + x.ToString() : x.ToString())).ToLower();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment