aboutsummaryrefslogtreecommitdiff
path: root/content/strings/encoding.go
diff options
context:
space:
mode:
authorRob Pike <r@golang.org>2013-10-22 23:05:47 -0700
committerRob Pike <r@golang.org>2013-10-22 23:05:47 -0700
commite81e54f7e23b828c2b42d5cf277251dda7511be1 (patch)
treeb52b973a65277b630c96b0671405c864332e16ae /content/strings/encoding.go
parent88eb9799109ea8009377f18e86be137ec64b3ac4 (diff)
go.blog/strings: blog post about strings
R=golang-dev, dan.kortschak, iant CC=golang-dev https://golang.org/cl/15460049
Diffstat (limited to 'content/strings/encoding.go')
-rw-r--r--content/strings/encoding.go19
1 files changed, 19 insertions, 0 deletions
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
+ }
+}