Pig*_*Pig 5 string algorithm go
我知道,为了计算一个子字符串的出现,我可以使用"strings.Count(,)".如果我想计算substring1或substring2的出现次数该怎么办?有没有比使用strings.count()编写另一个新行更优雅的方法?
使用正则表达式:
https://play.golang.org/p/xMsHIYKtkQ
aORb := regexp.MustCompile("A|B")
matches := aORb.FindAllStringIndex("A B C B A", -1)
fmt.Println(len(matches))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5985 次 |
| 最近记录: |