///<summary>
///功能:精確的按要求截取指定長度的字符串
///中文算2個(gè)英文算一個(gè)
///參數(shù):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標(biāo)簽
/// </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;
}
新聞熱點(diǎn)
疑難解答
圖片精選