I have a string of array. for example
"['a','b','c']"
which i want to convert to array of string as below
["a","b","c"]
can someone help me on this?
CodePudding user response:
var s = "['a','b','c']"
ss := strings.Split(strings.Trim(s, "[]"), ",")
a := make([]string, len(ss))
for i := range ss {
a[i] = strings.Trim(ss[i], "'")
}
out, err := json.Marshal(a)
if err != nil {
panic(err)
}
fmt.Println(string(out))
// output: ["a","b","c"]