Golang:int到切片的转换

Total golang (and programming) noob!

Given any six digit number, how could one output a slice where each character of that number is assigned an individual location within the slice?

For instance, a slice (let's call it s) containing all of these characters, would have s[0]=first digit, s[1]=second digit, s[2]=third digit and so on.

Any help would be greatly appreciated!

This is a two step process, first converting int to string, then iterating the string or converting to a slice. Because the built in range function lets you iterate each character in a string, I recommend keeping it as a string. Something like this;

 import "strconv"
 str := strconv.Itoa(123456)
 for i, v := range str {
      fmt.Println(v) //prints each char's ASCII value on a newline
      fmt.Printf("%c
", v) // prints the character value
 }