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