Here is a way to do this without using Regex:
public static string PascalToKebabCase(this string str) { if (string.IsNullOrEmpty(str)) return string.Empty; var builder = new StringBuilder(); builder.Append(char.ToLower(str.First())); foreach (var c in str.Skip(1)) { if (char.IsUpper(c)) { builder.Append('-'); builder.Append(char.ToLower(c)); } else { builder.Append(c); } } return builder.ToString(); }
You will have problems with known abbreviations that use uppercase letters. For example: COMObject . This solution obviously did not work.
source share