tags:

views:

176

answers:

5

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

+24  A: 
int RowFormat = "grtkj####mfr".Count(ch => ch == '#');
Kamarey
Perfectly succinct. +1
Randolpho
Also, when posting a LINQ query, it is still sometimes a good idea to mention that it only works >3.5 unless the questions specifically mentions version. No better answer given the constraints though.
NickLarsen
+1  A: 

Check this

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

hope that will help.

Asim Sajjad
+2  A: 

With LINQ (that's all the rage these days):

int RowFormat = drr[3].Count(x => x == '#');
Vilx-
+6  A: 

This question already holds the answer to what you're looking for.

Mat Nadrofsky
A: 
int RowFormat = new Regex("#").Matches("grtkj####mfr").Count;
runrunraygun