asp.net替換和恢復(fù)html特殊字符
更新時(shí)間:2008年05月10日 21:41:29 作者:
替換html中的特殊字符需要進(jìn)行替換的文本。替換完的文本。
/// <summary>
/// 替換html中的特殊字符
/// </summary>
/// <param name="theString">需要進(jìn)行替換的文本。</param>
/// <returns>替換完的文本。</returns>
public string HtmlEncode(string theString)
{
theString=theString.Replace(">", ">");
theString=theString.Replace("<", "<");
theString=theString.Replace(" ", " ");
theString=theString.Replace(" ", " ");
theString=theString.Replace("\"", """);
theString=theString.Replace("\'", "'");
theString=theString.Replace("\n", "<br/> ");
return theString;
}
/// <summary>
/// 恢復(fù)html中的特殊字符
/// </summary>
/// <param name="theString">需要恢復(fù)的文本。</param>
/// <returns>恢復(fù)好的文本。</returns>
public string HtmlDiscode(string theString)
{
theString=theString.Replace(">", ">");
theString=theString.Replace("<", "<");
theString=theString.Replace(" "," ");
theString=theString.Replace(" "," ");
theString=theString.Replace(""","\"");
theString=theString.Replace("'","\'");
theString=theString.Replace("<br/> ","\n");
return theString;
}
/// 替換html中的特殊字符
/// </summary>
/// <param name="theString">需要進(jìn)行替換的文本。</param>
/// <returns>替換完的文本。</returns>
public string HtmlEncode(string theString)
{
theString=theString.Replace(">", ">");
theString=theString.Replace("<", "<");
theString=theString.Replace(" ", " ");
theString=theString.Replace(" ", " ");
theString=theString.Replace("\"", """);
theString=theString.Replace("\'", "'");
theString=theString.Replace("\n", "<br/> ");
return theString;
}
/// <summary>
/// 恢復(fù)html中的特殊字符
/// </summary>
/// <param name="theString">需要恢復(fù)的文本。</param>
/// <returns>恢復(fù)好的文本。</returns>
public string HtmlDiscode(string theString)
{
theString=theString.Replace(">", ">");
theString=theString.Replace("<", "<");
theString=theString.Replace(" "," ");
theString=theString.Replace(" "," ");
theString=theString.Replace(""","\"");
theString=theString.Replace("'","\'");
theString=theString.Replace("<br/> ","\n");
return theString;
}
您可能感興趣的文章:
- ASP.NET對(duì)HTML頁(yè)面元素進(jìn)行權(quán)限控制(一)
- ASP.NET對(duì)HTML頁(yè)面元素進(jìn)行權(quán)限控制(二)
- ASP.NET對(duì)HTML頁(yè)面元素進(jìn)行權(quán)限控制(三)
- Asp.net動(dòng)態(tài)生成html頁(yè)面的方法分享
- Asp.net 動(dòng)態(tài)加載用戶自定義控件,并轉(zhuǎn)換成HTML代碼
- asp.net(C#) 動(dòng)態(tài)添加非ASP的標(biāo)準(zhǔn)html控件(如添加Script標(biāo)簽)
- 利用ASP.NET技術(shù)動(dòng)態(tài)生成HTML頁(yè)面
- asp.net 圖片驗(yàn)證碼的HtmlHelper
- ASP.NET 頁(yè)面刷新的實(shí)現(xiàn)方法(包括html,js)
- asp.net HTML文件上傳標(biāo)簽
- asp.net下URL網(wǎng)址重寫成.html格式、RSS、OPML的知識(shí)總結(jié)
- asp.net正則表達(dá)式刪除指定的HTML標(biāo)簽的代碼
- ASP.NET動(dòng)態(tài)增加HTML元素的方法實(shí)例小結(jié)
相關(guān)文章
ASP.NET Core優(yōu)雅的在開發(fā)環(huán)境保存機(jī)密(User Secrets)
這篇文章主要為大家詳細(xì)介紹了ASP.NET Core如何優(yōu)雅的在開發(fā)環(huán)境保存機(jī)密User Secrets,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-05-05Asp.net 頁(yè)面導(dǎo)航的幾種方法與比較 分享
在ASP.NET應(yīng)用中,Web表單之間的導(dǎo)航有多種方式:用超級(jí)鏈接,用Response.Redirect,用Server.Transfer,或者用Server.Execute。本文將分析這四種導(dǎo)航方式的異同及其優(yōu)缺點(diǎn),幫助你選擇最佳的導(dǎo)航方式。2013-07-07.NET連接數(shù)據(jù)庫(kù)以及基本的增刪改查操作教程
這篇文章主要給大家介紹了關(guān)于.NET連接數(shù)據(jù)庫(kù)以及基本的增刪改查操作教程的相關(guān)資料,對(duì)于剛?cè)腴T的新手們來說是個(gè)很好的入門教程,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。2018-01-01asp.net 通過UserAgent判斷智能設(shè)備(Android,IOS)
搜集了比較全的 智能設(shè)備 的 Agent,然后又寫了程序,需要的朋友可以參考下2011-10-10在阿里云函數(shù)計(jì)算上部署.NET Core 3.1的方法
這篇文章主要介紹了在阿里云函數(shù)計(jì)算上部署.NET Core 3.1的方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-07-07asp.net中Datalist使用數(shù)字分頁(yè)的實(shí)現(xiàn)方法
asp.net下Datalist使用數(shù)字分頁(yè)的實(shí)現(xiàn)代碼,需要的朋友可以參考下。2010-10-10Linux服務(wù)器下利用Docker部署.net Core項(xiàng)目的全過程
這篇文章主要給大家介紹了關(guān)于在Linux服務(wù)器下利用Docker部署.net Core項(xiàng)目的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用.net Core具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2019-07-07