簡體   English   中英

如何從字符串中刪除所有HTML格式

[英]How to remove all HTML formatting from string

我目前正在使用WebClient類在WinForms應用程序中查詢來自C#的php腳本。

php腳本返回以html格式化的錯誤,因為它們旨在顯示在網頁中。

例:

<br />
<b>Error:</b> Undefined value xyz in /var/www/sdsd/sdsd/asdsd.php
<br />

響應代碼可能更復雜,包含其他HTML類型。

有什么我可以做的,以允許.NET解釋HTML並返回用戶期望看到的值。 理想情況下,我希望收到"Error: Undefined value xyz in /var/www/sdsd/sdsd/asdsd.php"

有很多方法可以做到這一點,快速谷歌返回stackoverflow - 剝離html標簽dotnetperls - 刪除我認為滿足您的要求的HTML標簽

你的C#腳本帶回html標簽的原因是因為當它讀取php標簽並從頁面獲取字符串時,它不會從html中解碼它。

你要做的只是將它添加到c#腳本中的hmtl字符串中

string StringFromPHPPage = StringFromPHPPage.server.htmldecode();
//that decodes the html tags.

我想你正在尋找這樣的東西:

 htmlinput =
 "<br /> <b>Error:</b> Undefined value xyz in /var/www/sdsd/sdsd/asdsd.php <br />"

 nonhtmloutput =
 Regex.Replace(htmlinput,@"\<.*?\>", String.Empty)

一個簡單的正則表達式,用於清除<>括號和括號中的任何內容

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM