1. 來張 效果圖 (簡陋的界面 湊合著看吧)
2. 代碼
[csharp] www.2cto.com
private void button1_Click(object sender, EventArgs e)
{
string sin = txtsid.Text;
int alpha = 0;
int num = 0;
int spc = 0;
for (int i = 0; i < sin.Length; i++)
{
string ch = sin.Substring(i, 1);
if (ch == " ")
spc += 1;
else if (char.IsNumber(ch, 0))
{
num += 1;
}
else if (char.IsUpper(ch, 0) | char.IsLower(ch, 0))
{
alpha += 1;
}
}
MessageBox.Show("空格=" + spc + ",數字=" + num + ",字母=" + alpha);
}