mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 03:06:41 +08:00
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:
@@ -61,11 +61,14 @@ strings.Index(s, str string) int
|
|||||||
strings.LastIndex(s, str string) int
|
strings.LastIndex(s, str string) int
|
||||||
```
|
```
|
||||||
|
|
||||||
如果 `ch` 是非 ASCII 编码的字符,建议使用以下函数来对字符进行定位:
|
如果需要查询非 ASCII 编码的字符在父字符串中的位置,建议使用以下函数来对字符进行定位:
|
||||||
|
|
||||||
```go
|
```go
|
||||||
strings.IndexRune(s string, r rune) int
|
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)
|
示例 4.14 [index_in_string.go](examples/chapter_4/index_in_string.go)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user