过滤掉空格( /r/n) 和html标签

 

显示文章时 过滤掉空格( /r/n) 和html标签

<%# IWebSiteLib.Tools.InterceptCharacter(Regex.Replace(Eval("productcontent").ToString(), "<.+?>|&nbsp;|(\\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;
            }
        }

 

 

posted @ 2009-04-10 18:47  zmxmiss  阅读(2497)  评论(0编辑  收藏  举报