字符串首字母转大写和小写
// FirstToUpper Convert the first letter of the string to uppercase.
func FirstToUpper(str string) string {
s := []rune(str)
if len(s) == 0 {
return str
}
if s[0] >= 65 && s[0] <= 90 {
return str
}
if s[0] >= 97 && s[0] <= 122 {
s[0] = s[0] - 32
}
return string(s)
}
// FirstToLower Convert the first letter of the string to lowercase.
func FirstToLower(str string) string {
s := []rune(str)
if len(s) == 0 {
return str
}
if s[0] >= 97 && s[0] <= 122 {
return str
}
if s[0] >= 65 && s[0] <= 90 {
s[0] += 32
}
return string(s)
}