-
-
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
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
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