fix bug
This commit is contained in:
parent
b8a47fbf1d
commit
13d410f2b8
34
str.go
34
str.go
@ -3,6 +3,8 @@
|
|||||||
package str
|
package str
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -89,14 +91,24 @@ func MapsKeysString(imap interface{}) string {
|
|||||||
return strings.Join(keys, ",")
|
return strings.Join(keys, ",")
|
||||||
}
|
}
|
||||||
|
|
||||||
//// CHARSTRING string = "" //will initialize by init function
|
// string json to string map to string
|
||||||
//// func init() {
|
func JsonstrToStrMap(jsonstr string) (m map[string]string) {
|
||||||
//// NUMBERSTRING = "0123456789"
|
err := json.Unmarshal([]byte(jsonstr), &m)
|
||||||
//// CHARSTRING = NUMBERSTRING
|
if err != nil {
|
||||||
//// for i := 'a'; i <= 'z'; i++ {
|
panic(fmt.Sprintf("Jsonstr[%s] To MapString failed:%s", jsonstr, err.Error()))
|
||||||
//// CHARSTRING = CHARSTRING + string(i)
|
}
|
||||||
//// }
|
return m
|
||||||
//// for i := 'A'; i <= 'Z'; i++ {
|
}
|
||||||
//// CHARSTRING = CHARSTRING + string(i)
|
|
||||||
//// }
|
// string to string map to string
|
||||||
//// }
|
// example: "K1:V1;K2:V2"
|
||||||
|
// => {K1:V1, K2:V2}
|
||||||
|
func StringToStrMap(str string, sep1, sep2 string) (m map[string]string) {
|
||||||
|
m = map[string]string{}
|
||||||
|
for _, kvstr := range strings.Split(str, sep1) {
|
||||||
|
if kv := strings.SplitN(kvstr, sep2, 2); len(kv) == 2 {
|
||||||
|
m[kv[0]] = kv[1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return m
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user