Skip to content

Instantly share code, notes, and snippets.

@itcuihao
Created May 15, 2020 07:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itcuihao/75879b54e4936ae62aa4bdf279349398 to your computer and use it in GitHub Desktop.
Save itcuihao/75879b54e4936ae62aa4bdf279349398 to your computer and use it in GitHub Desktop.
```
// 驼峰式写法转为下划线写法
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