對特殊字符串編碼存入數據庫

對字符串編碼的處理,然後保存到數據庫中:實踐中的一段例子

mycomm.Parameters["@neirong"].Value =htmlencode(neirong.Text.ToString());
private string htmlencode(string str)
{
 str=Server.HtmlEncode(str);//對字符串進行編碼
 str=str.Replace("/r/n","<br>");
 char ch;
 ch=(char)32;//空格的編碼爲32
 str=str.Replace(ch.ToString(),"");
 return str;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章