![](/img/trans.png)
[英]How to remove a string from a flowdocument paragraph without disturbing the MarkUp?
[英]Remove html markup from string
我正在從數據庫中讀取一個字段並顯示在 GridView 中,並且在該字段中它包含文本中的<br/>
標記。 所以我試圖從代碼中刪除這些,但是當我檢查e.Row.Cells[index].Text
的值時,它不包含<br/>
並且有;br/>
反而。
因此,我嘗試創建一個 function,它刪除任何以<
開頭並以>
結尾或以&
開頭並以;
結尾的 substring。 . 代碼刪除了<>
但它仍然顯示br/
代碼:
index = gv.Columns.HeaderIndex("Message");
if (index > 0)
{
string message = RemoveHTMLMarkup(e.Row.Cells[index].Text);
e.Row.Cells[index].Text = message;
}
static string RemoveHTMLMarkup(string text)
{
return Regex.Replace(Regex.Replace(text, "<.+?>", string.Empty), "&.+?;", string.Empty);
}
如何刪除<br/>
標簽?
由於這是文字字符串,因此您(sh | c)僅使用String.Replace()
:
static string RemoveHTMLNewLines(string text)
{
return text.Replace("<br/>", string.Empty);
}
或根據需要替換為Environment.NewLine
。
要么
如果您有足夠的時間學習和使用,請使用HtmlAgilityPack軟件包。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.