Convert Int Array To String Separated By ','


Answer :

Make IDs a []string and convert the integers when you append them



var IDs []string
for _, i := range []int{1, 2, 3, 4} {
IDs = append(IDs, strconv.Itoa(i))
}

fmt.Println(strings.Join(IDs, ", "))


https://play.golang.org/p/xrfuMRjgiI



I would prefer to use json.Marshal. It is much simple and easy to use.



data := []int{100, 200, 300}
s, _ := json.Marshal(data)

fmt.Println(strings.Trim(string(s), "[]"))


GoPlaygroundLink



I hope this helps you. Please feel free to ask in case of doubts. WebsiteLink



Comments

Popular posts from this blog

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android How Can I Convert A String To A Editable