Convert string to []int?

Yes. I would:

  • Split the string into its “fields,” as Go calls them, with the strings.Fields function.
  • Then use strconv.Atoi to convert each string field into an integer (assuming the integers are base10 and can fit into an int):

https://play.golang.org/p/5eIdBwvbKjn

2 Likes