github.com/spotify/syslog-redirector-golang@v0.0.0-20140320174030-4859f03d829a/blog/content/strings/encoding.go (about) 1 // Copyright 2013 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package main 6 7 import ( 8 "fmt" 9 "unicode/utf8" 10 ) 11 12 func main() { 13 const nihongo = "日本語" 14 for i, w := 0, 0; i < len(nihongo); i += w { 15 runeValue, width := utf8.DecodeRuneInString(nihongo[i:]) 16 fmt.Printf("%#U starts at byte position %d\n", runeValue, i) 17 w = width 18 } 19 }