go-字符串⽣成数据库字段package main
import (
"fmt"
"regexp"
"strings"
)
func main() {
msg := `Days:  billOverdueDays,
Status: enumeration.BOOL__TRUE,`
dbFields := make([]string, 0)
msgArray := strings.Split(msg, ",")
for _, field := range msgArray {
oracle字符串转数组tmp := compressStr(strings.Split(field, ":")[0])
dbFields = append(dbFields, tmp)
}
ret := make([]string, 0)
for _, value := range dbFields {
tmp := ""
for _, byte := range value {
if string(byte) >= "A" && string(byte) <= "Z" {
tmp += "_" + strings.ToLower(string(byte))
} else {
tmp += string(byte)
}
}
tmp = "F" + tmp
tmp = strings.Replace(tmp, "_i_d", "_id", 1)
tmp = strings.Replace(tmp, "_n_o", "_no", 1)
ret = append(ret, tmp)
}
ret = ret[:len(ret)-1]
for _, value := range ret {
fmt.Println(value)
}
}
func compressStr(str string) string {
if str == "" {
return""
}
//匹配⼀个或多个空⽩符的正则表达式
reg := regexp.MustCompile("\\s+")
return reg.ReplaceAllString(str, "")
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。