Converts a string to kebab case.
Use strings.Fields()
to get the words in the string, strings.Join()
to combine them using "-"
as the separator.
代码实现
import "strings"
func ToKebab(s string) string {
return strings.Join(strings.Fields(s), "-")
}
使用样例
ToKebab("some text") // "some-text"