c# count characters in string code example

Example 1: c# count number of occurrences in string

char myChar = 'x';
string myString = "xyz";

int count = myString.Count(s => s == myChar);

Example 2: find character from string c# count

int count = Regex.Matches(test, "word").Count;

Example 3: how to count letters in c#

int numberOfLetters = yourWord.Length;

Example 4: count number of characters in an int c#

/// You can do this two ways.
/// First way (below)
public int getcharsforeach(int l) {
  	int charnum = 0;
	foreach (char c in l.ToString()) {
    	charnum += 1;
    }
  	return charnum;
}
/// Second way (below)
public int getcharlength(int l) {
	int letters = l.ToString().Length;
  	return letters;
}