关于c#:如何在字符串中计算’#’?

how to get count of '#' in a string?

本问题已经有最佳答案,请猛点这里访问。

Possible Duplicate:
How would you count occurences of a string within a string (C#)?

如何获取字符串中出现""的次数?

有点像int RowFormat = drr[3].ToString("#").Length;

示例字符串"grtkj mfr"

rowformat必须返回4

是的,^.net 3.5


1
int RowFormat ="grtkj####mfr".Count(ch => ch == '#');


(这是茶与LINQ的愤怒,这些天):P></

1
int RowFormat = drr[3].Count(x => x == '#');


check thisP></

1
"grtkj####mfr".Split(new char[]{'#'}).Length-1

希望这会帮助。P></


1
int RowFormat = new Regex("#").Matches("grtkj####mfr").Count;