public int GetStringLength(string str)//判断textbox字节长度
{
if (str != "")
{
int strlen = 0;
ASCIIEncoding strData = new ASCIIEncoding();
byte[] strBytes = strData.GetBytes(str);
for (int i = 0; i <= strBytes.Length - 1; i++)
{
if (strBytes[i] == 63)
strlen++;
strlen++;
}
return strlen;
}
else
{
return 0;
}
}
例如,参数是textbox1.text