1
0
mirror of https://github.com/chai2010/advanced-go-programming-book.git synced 2025-05-24 04:22:22 +00:00

ch1-3-fix code

This commit is contained in:
sfw 2018-08-08 11:39:28 +08:00
parent cd7d315586
commit e34c7c9e91

View File

@ -253,7 +253,7 @@ for i := 0; i < len(s); i++ {
Go语言除了`for range`语法对UTF8字符串提供了特殊支持外还对字符串和`[]rune`类型的相互转换提供了特殊的支持。
```go
fmt.Printf("%#v\n", []rune("Hello, 世界")) // []int32{19990, 30028}
fmt.Printf("%#v\n", []rune("世界")) // []int32{19990, 30028}
fmt.Printf("%#v\n", string([]rune{'世', '界'})) // 世界
```
@ -318,9 +318,9 @@ func bytes2str(s []byte) (p string) {
func str2runes(s []byte) []rune {
var p []int32
for len(s) > 0 {
r, size := utf8.DecodeRuneInString(s)
r, size := utf8.DecodeRuneInString(s)
p = append(p, r)
s = s[size:]
s = s[size:]
}
return []rune(p)
}