Last active
August 20, 2025 07:40
-
-
Save wjkoh/7521ccc82e42c85262bb7bde7557f56e to your computer and use it in GitHub Desktop.
Go: camelCase
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
| 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