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

530 Valid Hostname Is Expected When Setting Up IIS 10 For Multiple Sites

C Perror Example

Converting A String To Int In Groovy