Created
May 15, 2020 07:21
-
-
Save itcuihao/75879b54e4936ae62aa4bdf279349398 to your computer and use it in GitHub Desktop.
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
``` | |
// 驼峰式写法转为下划线写法 | |
func hump2Underscore(name string) string { | |
builder:=strings.Builder{} | |
for i, r := range name { | |
if unicode.IsUpper(r) { | |
if i != 0 { | |
builder.WriteByte('_') | |
} | |
builder.WriteRune(unicode.ToLower(r)) | |
} else { | |
builder.WriteRune(r) | |
} | |
} | |
return builder.String() | |
} | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment