Number of occurrences of a character in a string

The Solution to Number of occurrences of a character in a string is


You could do this:

int count = test.Split('&').Length - 1;

Or with LINQ:

test.Count(x => x == '&');

~ Answered on 2012-04-30 22:41:49


Most Viewed Questions: