fmt.Printf("hex bytes: ") for i := 0; i < len(placeOfInterest); i++ { fmt.Printf("%x ", placeOfInterest[i]) } fmt.Printf("\n") }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
package main
import"fmt"
func main() { const nihongo = "日本語" for index, runeValue := range nihongo { fmt.Printf("%#U starts at byte position %d\n", runeValue, index) }
const str = "abc" for index, runeValue := range str { fmt.Printf("%#U starts at byte position %d\n", runeValue, index) } }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
package main
import ( "fmt" "unicode/utf8" )
func main() { const nihongo = "日本語" for i, w := 0, 0; i < len(nihongo); i += w { runeValue, width := utf8.DecodeRuneInString(nihongo[i:]) fmt.Printf("%#U starts at byte position %d\n", runeValue, i) w = width } }