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