///<summary>
///功能:精确的按要求截取指定长度的字符串
///中文算2个英文算一个
///参数:str 待截取字符,len 截取长度 symbol 表示字符(....)
///</summary>
public static string gottopic(string str,int len,string symbol)
{
int count = 0;
string strtemp = "";
str = nohtml(str);
for (int i = 0; i < str.length; i++)
{
if (math.abs(((int)(str.substring(i, 1).tochararray())[0])) > 255)
{
count += 2;
}else
{
count += 1;
}
if (count <= len)
{
strtemp += str.substring(i, 1);
}
else
{
return strtemp + symbol;
}
}
return str;
}
/// <summary>
/// 过滤掉html标签
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static string nohtml(string str)
{
str = regex.replace(str, @"(/<.[^/<]*/>)", " ", regexoptions.ignorepatternwhitespace | regexoptions.ignorecase);
str = regex.replace(str, @"(/<//[^/<]*/>)"," ", regexoptions.ignorecase | regexoptions.ignorepatternwhitespace);
return str;
}
新闻热点
疑难解答