替换不文明词语和非法字符

//替换不文明词语和非法字符
string StrReplaceSk(string checkstr)
{
    
string repstr="";
    
if(Application["repstr"!= null)
    
{
        repstr 
= Application["repstr"].ToString();
    }

    
else
    
{
        Uri myUri 
=new Uri("http://www.XXXXXX.com/checkstr.txt");
        WebRequest req 
= WebRequest.Create(myUri);
        WebResponse result 
= req.GetResponse();
        Stream srepstr 
= result.GetResponseStream(); //得到是一个对象
        Encoding encode = Encoding.GetEncoding("UTF-8");
        StreamReader sr 
= new StreamReader(srepstr,encode );
        repstr 
=sr.ReadToEnd();
        Application.Lock();
        Application[
"repstr"= repstr;
        Application.UnLock();
    }


    
string[] reparr=repstr.Split('|');
    
foreach(string rep in reparr) 
    
{
        checkstr
=checkstr.Replace(rep,"");
    }

    
return checkstr;
}
posted @ 2006-09-17 15:02  wenanry  阅读(692)  评论(4)    收藏  举报