电脑故障

位置:IT落伍者 >> 电脑故障 >> 浏览文章

检测含有中文字符串的实际长度


发布日期:2022/9/17
 

string MyString = 中华人民共和国中央人民政府主席;

ASCIIEncoding MyData = new ASCIIEncoding();

byte[] MyBytes = MyDataGetBytes(MyString);

//MyLength 为字符串的实际长度

int MyLength= ;

for (int i = ; i <= MyBytesLength ; i++)

{

//判断是否为汉字或全脚符号

if (MyBytes[i] == )

{

MyLength++;

}

MyLength++;

}

String MyInfo =+MyString+ 共有+MyStringLengthToString()+个字符;

MyInfo += 实际长度为 + MyLengthToString() + 字节;

MessageBoxShow(MyInfo 信息提示 MessageBoxButtonsOK MessageBoxIconInformation);

上一篇:Panel加样式有时候无法浮动的问题

下一篇:VB 2005中开发新一代控制台应用程序