//字符是否為漢字
public bool IsChinese(char c)
{
return (int)c >=
}
//獲得字節長度
private int getLengthb(string str)
{
return System
}
//c#的中英文混合字符串截取指定長度
public string getStrLenB(string str
{
int Lengthb = getLengthb(str);
if (startidx +
{
return
}
int j =
int l =
int strw =
bool b = false;
string rstr =
for (int i =
{
char c = str[i];
if (j >= startidx)
{
rstr = rstr + c;
b = true;
}
if (IsChinese(c))
{
strw =
}
else
{
strw =
}
j = j + strw;
if (b)
{
l = l + strw;
if ((l+
}
}
return rstr;
}
private void button
{
MessageBox
MessageBox
MessageBox
}
From:http://tw.wingwit.com/Article/program/net/201311/12925.html