编写一个函数,该函数可以统计一个长度不限的字符串在另一个字符串中出现的次数。例如,假定输入的字符串为asd asasdfg asd as zx67 asd mklo,子字符串为as,则应当输出6。假如输入的字符串为:asd asdasdljfl lfjdsaasd ljfd,子字符串位asd,则应当输出4。请赐教,谢谢!
解决方案
40
需要那么麻烦吗?
var a = "asd asasdfg asd as zx67 asd mklo"; var b = "as"; var c = a.Split(new string[] { b }, StringSplitOptions.None).Length-1; Response.Write(c); a = "asd asdasdljfl lfjdsaasd ljfd"; b = "asd"; c = a.Split(new string[] { b }, StringSplitOptions.None).Length - 1; Response.Write(c);
任何人都能看懂的….结贴给分