5

Possible Duplicate:
How would you count occurences of a string 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

2
  • 2
    See this question: stackoverflow.com/questions/541954/… Commented Mar 16, 2010 at 13:20
  • thank you all <3 so many answers Commented Mar 16, 2010 at 13:26

4 Answers 4

26
int RowFormat = "grtkj####mfr".Count(ch => ch == '#');
Sign up to request clarification or add additional context in comments.

1 Comment

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.
2

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

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

Comments

1

Check this

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

hope that will help.

Comments

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.