給妳參考代碼:
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
label1.Text = string.Format("string count:{0}", GetCount(richTextBox1.Text));
}
private int GetCount(string str)
{
int cunt=0;
string[] strs = str.Split(new char[] { ' ' });
foreach(string tpStr in strs)
{
if(tpStr.ToLower().IndexOfAny(
new char[]{'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q',
'r','s','t','u','v','w','x','y','z'})>=0)
{
cunt++;
}
}
return cunt;
}