From 87a49f6d96630f592e1686000840ba74ed2c1b02 Mon Sep 17 00:00:00 2001 From: crackedcd Date: Tue, 11 Sep 2018 20:59:45 +0800 Subject: [PATCH] Update 04.7.md (#541) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update 04.7.md 原文存在歧义, 导致翻译时存在疑惑. * Update 04.7.md 修复了原书有误的strings.IndexRune()函数说明. * Update 04.7.md follow owner's request "s/GO/Go". --- eBook/04.7.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/eBook/04.7.md b/eBook/04.7.md index c8ed5db..7186df1 100644 --- a/eBook/04.7.md +++ b/eBook/04.7.md @@ -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)