过滤掉空格( /r/n) 和html标签
显示文章时 过滤掉空格( /r/n) 和html标签
<%# IWebSiteLib.Tools.InterceptCharacter(Regex.Replace(Eval("productcontent").ToString(), "<.+?>| |(\\r\\n)|\\s", ""), 60)%>
IWebSiteLib.Tools.InterceptCharacter为截取字符串的方法
Code
public static string InterceptCharacter(string Character, int extent)
{
string TempString = "";
if (System.Text.Encoding.Default.GetByteCount(Character) > extent)
{
int iCount = Character.Length;
while (true)
{
iCount--;
TempString = Character.Substring(0, iCount);
if (System.Text.Encoding.Default.GetByteCount(TempString) <= extent)
{
break;
}
}
return TempString + "";
}
else
{
return Character;
}
}
public static string InterceptCharacter(string Character, int extent)
{
string TempString = "";
if (System.Text.Encoding.Default.GetByteCount(Character) > extent)
{
int iCount = Character.Length;
while (true)
{
iCount--;
TempString = Character.Substring(0, iCount);
if (System.Text.Encoding.Default.GetByteCount(TempString) <= extent)
{
break;
}
}
return TempString + "";
}
else
{
return Character;
}
}