计算字符串在另一个字符串中出现的次数
有没有办法计算一个字符串在另一个字符串中出现的次数。例如。 “bla/hsi/sgg/shrgsvs/”中“/”出现了多少次= 4.
Is there any way of counting how many times one string occurs in another. Eg. how many times does "/" appear in "bla/hsi/sgg/shrgsvs/"= 4.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你可以这样做:
但这确实又快又脏。其他人可能很快就会提出更好的答案。
编辑:
现在我想了一下,这也可能有效:
尽管我仍然认为必须有更好的方法......
You could do:
But that's really quick and dirty. Someone else might come up with a better answer shortly.
EDIT:
Now that I think about it, this might work too:
Although I still think there's gotta be a better way...