Skip to content

Instantly share code, notes, and snippets.

@wjkoh
Last active August 20, 2025 07:40
Show Gist options
  • Select an option

  • Save wjkoh/7521ccc82e42c85262bb7bde7557f56e to your computer and use it in GitHub Desktop.

Select an option

Save wjkoh/7521ccc82e42c85262bb7bde7557f56e to your computer and use it in GitHub Desktop.
Go: camelCase
package main
import (
"fmt"
"strings"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)
func main() {
// OUTPUT: integratedEngineering5Year(BscWithAYearInIndustry)
fmt.Println(camelCase("INTEGRATED ENGINEERING 5 Year (BSC with a Year in Industry)"))
}
func camelCase(s string) string {
titleCased := cases.Title(language.English).String(s)
words := strings.Fields(titleCased)
if len(words) == 0 {
return ""
}
words[0] = strings.ToLower(words[0])
return strings.Join(words, "")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment