mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-11 20:02:56 +08:00
Update 06.7.md (#799)
This commit is contained in:
@@ -28,7 +28,7 @@ func callback(y int, f func(int, int)) {
|
||||
|
||||
将函数作为参数的最好的例子是函数 `strings.IndexFunc()`:
|
||||
|
||||
该函数的签名是 `func IndexFunc(s string, f func(c rune) bool) int`,它的返回值是在函数 `f(c)` 返回 true、-1 或从未返回时的索引值。
|
||||
该函数的签名是 `func IndexFunc(s string, f func(c rune) bool) int`,它的返回值是字符串s中第一个使函数`f(c)`返回`true`的Unicode字符的索引值。如果找不到,则返回-1。
|
||||
|
||||
例如 `strings.IndexFunc(line, unicode.IsSpace)` 就会返回 `line` 中第一个空白字符的索引值。当然,您也可以书写自己的函数:
|
||||
|
||||
|
Reference in New Issue
Block a user