Update 06.7.md (#799)

This commit is contained in:
Xuing
2021-10-23 11:59:15 +08:00
committed by GitHub
parent 89f892e18c
commit acb40ab815

View File

@@ -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` 中第一个空白字符的索引值。当然,您也可以书写自己的函数: