@@ -103,6 +103,60 @@ public static string ToPascalCase(Enum value) {
103103 return ToPascalCase ( value . ToString ( ) ) ;
104104 }
105105
106+ /// <summary>
107+ /// Converts the specified <paramref name="str"/> to a kebab cased string (lower case words separated by hyphens).
108+ /// </summary>
109+ /// <param name="str">The string to be converted.</param>
110+ /// <returns>The kebab cased string.</returns>
111+ public static string ToKebabCase ( string str ) {
112+
113+ // Replace invalid characters
114+ str = Regex . Replace ( str ?? "" , "[\\ W_]+" , " " ) . Trim ( ) ;
115+
116+ // Replace multiple whitespaces
117+ str = Regex . Replace ( str , "[ ]{2,}" , " " ) ;
118+
119+ // Convert to lower case (with upper case letters prefixed with hyphens)
120+ return Regex . Replace ( str , @"(\p{Ll})(\p{Lu})" , "$1-$2" ) . Replace ( " " , "-" ) . Replace ( "--" , "-" ) . ToLower ( ) ;
121+
122+ }
123+
124+ /// <summary>
125+ /// Converts the name of the specified enum <paramref name="value"/> to a kebab cased string (lower case words separated by hyphens).
126+ /// </summary>
127+ /// <param name="value">The enum value to be converted.</param>
128+ /// <returns>The camel cased string.</returns>
129+ public static string ToKebabCase ( Enum value ) {
130+ return ToKebabCase ( value . ToString ( ) ) ;
131+ }
132+
133+ /// <summary>
134+ /// Converts the specified <paramref name="str"/> to a train cased string (upper case words separated by hyphens).
135+ /// </summary>
136+ /// <param name="str">The string to be converted.</param>
137+ /// <returns>The train cased string.</returns>
138+ public static string ToTrainCase ( string str ) {
139+
140+ // Replace invalid characters
141+ str = Regex . Replace ( str ?? "" , "[\\ W_]+" , " " ) . Trim ( ) ;
142+
143+ // Replace multiple whitespaces
144+ str = Regex . Replace ( str , "[ ]{2,}" , " " ) ;
145+
146+ // Convert to upper case (with upper case letters prefixed with hyphens)
147+ return Regex . Replace ( str , @"(\p{Ll})(\p{Lu})" , "$1-$2" ) . Replace ( " " , "-" ) . Replace ( "--" , "-" ) . ToUpper ( ) ;
148+
149+ }
150+
151+ /// <summary>
152+ /// Converts the name of the specified enum <paramref name="value"/> to a train cased string (upper case words separated by hyphens).
153+ /// </summary>
154+ /// <param name="value">The enum value to be converted.</param>
155+ /// <returns>The camel cased string.</returns>
156+ public static string ToTrainCase ( Enum value ) {
157+ return ToTrainCase ( value . ToString ( ) ) ;
158+ }
159+
106160 /// <summary>
107161 /// Converts the specified <paramref name="str"/> to a lower case string with words separated by underscores.
108162 /// </summary>
0 commit comments