【求助】c#怎么文本框的内容数量
大家好c# vs2008
有一个文本框
可以如数任何内容
有一个按钮
一点就显示
messagebox.show("汉字"+a+"个"+"字母"+b"个");
把textbox里面的 汉字 和字母 呀 还有字符的个数 统计出来!
谢谢!
2010-09-04 20:00
2010-09-06 18:33
程序代码:string MyString = "中华人民共和国中央人民政府主席毛泽东,1950年。";
ASCIIEncoding MyData = new ASCIIEncoding();
byte[] MyBytes = MyData.GetBytes(MyString);
//MyLength 为字符串的实际长度
int MyLength= 0;
for (int i = 0; i <= MyBytes.Length - 1; i++)
{
//判断是否为汉字或全脚符号
if (MyBytes[i] == 63)
{
MyLength++;
}
MyLength++;
}
String MyInfo ="“"+MyString+ "”共有"+MyString.Length.ToString()+"个字符,";
MyInfo += "实际长度为" + MyLength.ToString() + "字节。";
MessageBox.Show(MyInfo, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); 
2010-09-06 20:26
2010-09-06 22:55

2010-09-07 09:22
2010-09-07 12:31
2010-09-07 13:10
2010-09-07 22:03
2010-09-11 23:35