In this example, the string is converted to a slice of runes using []rune. We then loop over it and display the characters.
Iterating over a string will normally give you the runes within that string, so the conversion wouldn't be necessary, see this playground snippet as an example play.golang.org/p/LkdB8zO4Cu_d.
Iterating over a string will normally give you the runes within that string, so the conversion wouldn't be necessary, see this playground snippet as an example play.golang.org/p/LkdB8zO4Cu_d.
Also from Effective Go,
You're right Andrew. Thanks for pointing that out.
In addition to that, there's an even better way to access runes in a string:
which gives:
Yeah,
%c
would format it as a char, so you can avoid casting it to a string like I did with myfmt.Println
call.Very cool #TIL