shivakb
7/31/2018 - 6:26 AM

Simple C# extension method to convert a camel case string to underscore notation without any regex

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();
    }
}