import (
"strings"
"unicode"
)
/**
* @Author QY
* @Email 80013593@qq.com
* @Description //字符串首字母小写
* @Date 11:28 2023/2/5
* @Param
* @return
**/
func FirstLower(s string) string {
if s == "" {
return ""
}
return strings.ToLower(s[:1]) + s[1:]
}
/**
* @Author QY
* @Email 80013593@qq.com
* @Description //字符串首字母大写
* @Date 11:28 2023/2/5
* @Param
* @return
**/
func FirstUpper(s string) string {
if s == "" {
return ""
}
return strings.ToUpper(s[:1]) + s[1:]
}
// 下划线单词转为大写驼峰单词
func UderscoreToUpperCamelCase(s string) string {
tablenamelist := strings.Split(s, "_")
title := ""
for i := 0; i < len(tablenamelist); i++ {
strStart := string([]byte(tablenamelist[i])[:1])
strend := string([]byte(tablenamelist[i])[1:])
// 大驼峰表名 结构体使用
title += strings.ToUpper(strStart) + strend
}
return title
}
// 下划线单词转为小写驼峰单词
func UderscoreToLowerCamelCase(s string) string {
tablenamelist := strings.Split(s, "_")
title := ""
for i := 0; i < len(tablenamelist); i++ {
strStart := string([]byte(tablenamelist[i])[:1])
strend := string([]byte(tablenamelist[i])[1:])
// 小驼峰表名 js函数名和权限标识使用
if i == 0 {
title += strings.ToLower(strStart) + strend
} else {
title += strings.ToUpper(strStart) + strend
}
}
return title
}
// 驼峰单词转下划线单词
func CamelCaseToUdnderscore(s string) string {
var output []rune
for i, r := range s {
if i == 0 {
output = append(output, unicode.ToLower(r))
} else {
if unicode.IsUpper(r) {
output = append(output, '_')
}
output = append(output, unicode.ToLower(r))
}
}
return string(output)
}