Number of occurrences of a character in a string [duplicate]

You could do this:

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

Or with LINQ:

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

Leave a Comment