Last active
October 20, 2020 11:25
-
-
Save LazZiya/72b3f143fee0bcfa791652420b692ad7 to your computer and use it in GitHub Desktop.
Convert strings to kebab case https://dotnetfiddle.net/WSE6sy
This file contains 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 KebabConverter | |
{ | |
public static string ToKebabCase(this string str) | |
{ | |
// find and replace all parts that starts with one capital letter | |
var str1 = Regex.Replace(str, "[A-Z][a-z]+", m => $"-{m.ToString().ToLower()}"); | |
// find and replace all parts that are all capital letters | |
var str2 = Regex.Replace(str1, "[A-Z]+", m => $"-{m.ToString().ToLower()}"); | |
return str2.TrimStart('-'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment