Last active
January 3, 2019 09:04
-
-
Save jony4/776af05cbbf480d010ed21bd29a20e83 to your computer and use it in GitHub Desktop.
go ToUpperCamelCase
This file contains hidden or 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
var camelre = regexp.MustCompile(`_([a-z])`) | |
// ToUpperCamelCase is an NameFunc that converts strings from snake case to upper camel case. | |
func ToUpperCamelCase(s string) string { | |
return strings.ToUpper(string(s[0])) + camelre.ReplaceAllStringFunc(s[1:len(s)], func(s string) string { | |
return strings.ToUpper(s[1:len(s)]) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment