Count number of chars in a string
using System; using System.Collections.Generic; using System.Text; using System.Text.RegularExpressions; public class MainClass{ public static int NumberOfCharsInStr(ref string stringToSearch, char charToFind) { int count = 0; char[] chars = stringToSearch.ToCharArray(); foreach (char c in chars) { if (c == charToFind) { count++; } } return count; } }
String