Update 04.7.md (#541)

* Update 04.7.md

原文存在歧义, 导致翻译时存在疑惑.

* Update 04.7.md

修复了原书有误的strings.IndexRune()函数说明.

* Update 04.7.md

follow owner's request "s/GO/Go".
This commit is contained in:
crackedcd
2018-09-11 20:59:45 +08:00
committed by 无闻
parent 80b74f6d08
commit 87a49f6d96

View File

@@ -61,11 +61,14 @@ strings.Index(s, str string) int
strings.LastIndex(s, str string) int
```
如果 `ch`非 ASCII 编码的字符,建议使用以下函数来对字符进行定位:
如果需要查询非 ASCII 编码的字符在父字符串中的位置,建议使用以下函数来对字符进行定位:
```go
strings.IndexRune(s string, r rune) int
```
注: 原文为 "If ch is a non-ASCII character use strings.IndexRune(s string, ch int) int."
该方法在最新版本的 Go 中定义为 func IndexRune(s string, r rune) int
实际使用中的第二个参数 rune 可以是 rune 或 int, 例如 strings.IndexRune("chicken", 99) 或 strings.IndexRune("chicken", rune('k'))
示例 4.14 [index_in_string.go](examples/chapter_4/index_in_string.go)