total golang (and programming) noob!
given 6 digit number, how 1 output slice each character of number assigned individual location within slice?
for instance, slice (let's call s) containing of these characters, have s[0]=first digit, s[1]=second digit, s[2]=third digit , on.
any appreciated!
this 2 step process, first converting int string, iterating string or converting slice. because built in range function lets iterate each character in string, recommend keeping string. this;
import "strconv" str := strconv.itoa(123456) i, v := range str { fmt.println(v) //prints each char's ascii value on newline fmt.printf("%c\n", v) // prints character value }
Comments
Post a Comment