What is wrong with using string.Length?
// len will be 5
int len = "Hello".Length;
If you don't need the leading and trailing spaces :
str.Trim().Length
string yourWord = "Derp derp";
Console.WriteLine(new string(yourWord.Select(c => char.IsLetter(c) ? '_' : c).ToArray()));
Yields:
____ ____
You can simply use
int numberOfLetters = yourWord.Length;
or to be cool and trendy, use LINQ like this :
int numberOfLetters = yourWord.ToCharArray().Count();
and if you hate both Properties and LINQ, you can go old school with a loop :
int numberOfLetters = 0;
foreach (char letter in yourWord)
{
numberOfLetters++;
}
Source: Stackoverflow.com