From e81e54f7e23b828c2b42d5cf277251dda7511be1 Mon Sep 17 00:00:00 2001 From: Rob Pike Date: Tue, 22 Oct 2013 23:05:47 -0700 Subject: go.blog/strings: blog post about strings R=golang-dev, dan.kortschak, iant CC=golang-dev https://golang.org/cl/15460049 --- content/strings/encoding.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 content/strings/encoding.go (limited to 'content/strings/encoding.go') diff --git a/content/strings/encoding.go b/content/strings/encoding.go new file mode 100644 index 0000000..c0f15a4 --- /dev/null +++ b/content/strings/encoding.go @@ -0,0 +1,19 @@ +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +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 + } +} -- cgit v1.2.3