package main import ( "fmt" "unicode/utf8" ) func main() { const s = "สวัสดี" // Will output thte byte length and not the string length. fmt.Println("Len:", len(s)) for i := range len(s) { fmt.Printf("%x ", s[i]) } fmt.Println() fmt.Println("Rune Count: ", utf8.RuneCountInString(s)) for idx, runeValue := range s { fmt.Printf("%#U starts at %d\n", runeValue, idx) } fmt.Println("\nUsing DecodeRuneInString") for i, w := 0, 0; i < len(s); i += w { runeValue, width := utf8.DecodeRuneInString(s[i:]) fmt.Printf("%#U starts at %d\n", runeValue, i) w = width examineRune(runeValue) } } func examineRune(r rune) { if r == 't' { fmt.Println("found tee") } else if r == 'ส' { fmt.Println("found so sua") } }