在 GoFrame 的 gstr 模块中,你可以使用 gstr.Count 函数来统计字符串中某个子串出现的次数。以下是一个示例:
package main

import (
"fmt"
"github.com/gogf/gf/text/gstr"
)

func main() {
// 统计子串出现的次数
s := "apple orange banana apple orange apple"
substr := "apple"
count := gstr.Count(s, substr)

fmt.Printf("在字符串 \"%s\" 中,子串 \"%s\" 出现的次数为:%d\n", s, substr, count)
}

在这个示例中,gstr.Count 函数被用于统计字符串 s 中子串 "apple" 出现的次数。输出结果将显示子串出现的次数。




转载请注明出处:http://www.zyzy.cn/article/detail/7771/GoFrame