【发布时间】:2014-12-17 16:10:40
【问题描述】:
你能解释一下我如何以简单的方式找到某个字符串在一个大字符串中出现的次数吗? 示例:
string longString = "hello1 hello2 hello546 helloasdf";
“你好”这个词出现了四次。我怎样才能得到第四个。 谢谢
编辑:我也想知道如何找到两个单词的字符串,例如:
string longString = "hello there hello2 hello4 helloas hello there";
我想知道“hello there”出现的次数。
编辑 2:正则表达式方法对我来说是最好的(计数),但它找不到像这样的单词,例如: ">word”的单词,它会跳过它。帮忙?
【问题讨论】:
-
所以你需要比较“单词”和“部分单词”,但是你尝试了什么?
-
我在这里为 SQL 介绍了这个:同样的方法也可以(不需要正则表达式!):stackoverflow.com/questions/9789225/…
标签: c# string search count word