/// <summary>
/// 截取字符串并去掉图片
/// </summary>
/// <param name="content">要处理的字符串</param>
/// <param name="length">截取长度</param>
/// <param name="tail">尾部特定字符</param>
/// <returns></returns>
public static string CutWithoutPic(string content, int length, string tail)
{
int conlength = content.Length;
int begin = 0;
int end = 0;
int endcharlen = 3;
string result = "";
begin = content.ToLower().IndexOf("<img ", 0);
if (begin == -1)
{
begin = content.ToLower().IndexOf("<input type=\"image", 0);
if (begin != -1)
{
end = content.ToLower().IndexOf("/>", begin);
if (end == -1)
{
end = content.ToLower().IndexOf(">", begin);
endcharlen = 2;
}
if (end == -1)
end = content.ToLower().IndexOf("/ >", begin);
result += content.Substring(0, begin);
result += content.Substring(end + endcharlen);
}
}
result = content;
return CutString(result, length, tail);
}
/// <summary>
/// 按长度截取字符串并在尾部添加特定字符
/// </summary>
/// <param name="str">原字符串</param>
/// <param name="length">截取长度</param>
/// <param name="tail">尾部特定字符</param>
/// <returns>返回截取后含有尾部的字符串</returns>
public static string CutString(string str, int length, string tail)
{
if (string.IsNullOrEmpty(tail))
tail = "...";
if (str.Length < length)
return str;
else
return str.Substring(0, length) + tail;
}