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 { 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, "") }