Skip to content

Instantly share code, notes, and snippets.

@owulveryck
Created April 11, 2019 12:40
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 owulveryck/b361f0ad6a88b29ce599facf88a9214f to your computer and use it in GitHub Desktop.
Save owulveryck/b361f0ad6a88b29ce599facf88a9214f to your computer and use it in GitHub Desktop.
Simple snake_case to camel case converter (https://play.golang.org/p/RtAzmSgnnvM)
package main
import (
"fmt"
"regexp"
"strings"
)
func main() {
fmt.Println(toCamelCase("blo_bla_Di_bla"))
}
var link = regexp.MustCompile("(^[A-Za-z]|_[A-Za-z])")
func toCamelCase(str string) string {
return link.ReplaceAllStringFunc(str, func(s string) string {
r := strings.NewReplacer("_", "")
return strings.ToUpper(r.Replace(s))
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment