In Golang, the first letter of a string is usually presented in lowercase. This is due to Golang's naming convention, which follows a rule called "camel nomenclature" where the first letter of variable and function names is lowercase, while the first letter of type names and exported function names is uppercase. This naming convention helps improve code readability and consistency. When we write Golang code, it is important to follow naming conventions, which can make our code easier to understand and maintain. Therefore, remembering that the first letter of a string in Golang is lowercase is a rule worth remembering.
I want to change the first letter of a given string to uppercase. I looked into the cases and strings packages and the closest I found was cases.title
cases.Title(language.Und, cases.NoLower).String("MyString")
It can accept a second parameter cases.something
But this way, I can't find a way to achieve only lowering the first character.
Is it similar to this?
https://www.php.cn/link/f1558e79c0736bcc9770373fdf03dccb
func firstLetterToLower(s string) string { if len(s) == 0 { return s } r := []rune(s) r[0] = unicode.ToLower(r[0]) return string(r) }
The above is the detailed content of The first letter of the string in golang is lowercase. For more information, please follow other related articles on the PHP Chinese website!