输入内容(string类型的),统计字母/数字/空格的数量 [C#]
1. 来张 效果图 (简陋的界面 凑合着看吧)
2. 代码
[csharp] www.zzzyk.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);
}
补充:软件开发 , C# ,