s) + 1;
if (size < length)
{
sb.Append(content.Substring(pos, npos - pos));
}
else
{
if (!notr && next.IndexOf("/tr") == 0)
{
sb.Append(content.Substring(pos, npos - pos));
notr = true;
}
}
}
else if (next.IndexOf("td") == 0 || next.IndexOf("/td") == 0)
{
npos = content.IndexOf(">", pos) + 1;
if (size < length)
{
sb.Append(content.Substring(pos, npos - pos));
}
else
{
if (!notr)
{
sb.Append(content.Substring(pos, npos - pos));
}
}
}
else
{
npos = content.IndexOf(">", pos) + 1;
sb.Append(content.Substring(pos, npos - pos));
}
if (npos <= pos)
npos = pos + 1;
pos = npos;
}
else
{
if (size < length)
{
sb.Append(cur);
size++;
}
else
{
if (!firststop)
{
sb.Append("……");
firststop = true;
}
}
pos++;
}
}
return sb.ToString();
}
}
#endregion
View Code
注意:方法中的bool StripHTML参数表示是否以HTMl文本方式输出,如果为True的话表示去除HTML标签与样式,截取到的是纯文本,反之就是以HTMl文本输出。
这样我们就可以根据自己喜欢的方式来输出文本。
|