Possible Duplicate:
How would you count occurences of a str开发者_Python百科ing within a string (C#)?
how do I get the count of the occurrences of '#' in a string ?
something like int RowFormat = drr[3].ToString("#").Length;
example string "grtkj####mfr "
RowFormat must return 4
and yes ^_^ .NET 3.5
int RowFormat = "grtkj####mfr".Count(ch => ch == '#');
With LINQ (that's all the rage these days):
int RowFormat = drr[3].Count(x => x == '#');
Check this
"grtkj####mfr".Split(new char[]{'#'}).Length-1
hope that will help.
int RowFormat = new Regex("#").Matches("grtkj####mfr").Count;
精彩评论