日期:2014-05-18 浏览次数:20518 次
public static string getStr(string s,int l)
{
string temp = s ;
if (Regex.Replace(temp,"[^\x00-\xff]","zz",RegexOptions.IgnoreCase).Length<=l)
{
return temp;
}
for (int i=temp.Length;i>=0;i--)
{
temp = temp.Substring(0,i);
if (Regex.Replace(temp,"[^\x00-\xff]","zz",RegexOptions.IgnoreCase).Length<=l)
{
return temp + "";
}
}
return "";
}
函数中参数s是字符串,l是字节长度,比如:
string content = "中国人中国人";
content = getStr(content,3);
------解决方案--------------------
你想 一个汉字2字节 你截取一个字节 那截取出来的 是什么子
就拿“一”这字来说 你把截取其中一个字节出来 那是什么字?