当前位置: 首页>>编程示例 >>用法及示例精选 >>正文


GO Count用法及代码示例

GO语言"bytes"包中"Count"函数的用法及代码示例。

用法:

func Count(s, sep []byte) int

Count 计算 s 中 sep 的非重叠实例的数量。如果 sep 是一个空切片,则 Count 返回 1 + s 中 UTF-8 编码的代码点数。

例子:

package main

import (
    "bytes"
    "fmt"
)

func main() {
    fmt.Println(bytes.Count([]byte("cheese"), []byte("e")))
    fmt.Println(bytes.Count([]byte("five"), []byte(""))) // before & after each rune
}

输出:

3
5

相关用法


注:本文由纯净天空筛选整理自golang.google.cn大神的英文原创作品 Count。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。