How do I convert PascalCase to kebab-case with C#?
问题 How do I convert a string value in PascalCase (other name is UpperCamelCase) to kebab-case with C#? e.g. "VeryLongName" to "very-long-name" 回答1: Here is how to do that with a regular expression: public static class StringExtensions { public static string PascalToKebabCase(this string value) { if (string.IsNullOrEmpty(value)) return value; return Regex.Replace( value, "(?<!^)([A-Z][a-z]|(?<=[a-z])[A-Z])", "-$1", RegexOptions.Compiled) .Trim() .ToLower(); } } 回答2: Here's my solution using