2012-02-20 49 views
1

我有一個DecXpress報告和數據源顯示提起其中數據正在添加類似字符串沒有得到解碼

PRODUCT - APPLE<BR/>ITEM NUMBER - 23454</BR>LOT NUMBER 3343 <BR/> 

現在是它是如何在一個單元格顯示,所以我決定解碼,但沒有什麼工作,我試過HttpUtility.HtmlDecode,在這裏我正在嘗試WebUtility.HtmlDecode。

private void xrTableCell9_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e) 
{ 
    XRTableCell cell = sender as XRTableCell; 
    string _description = WebUtility.HtmlDecode(Convert.ToString(GetCurrentColumnValue("Description"))); 
    cell.Text = _description; 

} 

如何解碼數據源中此列的值?

謝謝

+2

描述是不是HTML編碼(解碼意味着得到< 2012-02-20 23:05:25

+0

你建議如何刪除
併爲報告插入一些中斷?然後呢?是否會執行一些String.replacing? – user710502 2012-02-20 23:11:42

回答

1

如果需要,以示與< />描述也,你需要使用的HTMLEncode


如果您需要從HTML

public static string ExtractTextFromHtml(this string text) 
     { 
      if (String.IsNullOrEmpty(text)) 
       return text; 
      var sb = new StringBuilder(); 
      var doc = new HtmlDocument(); 
      doc.LoadHtml(text); 
      foreach (HtmlNode node in doc.DocumentNode.SelectNodes("//text()")) 
      { 
       if (!String.IsNullOrWhiteSpace(node.InnerText)) 
        sb.Append(HtmlEntity.DeEntitize(node.InnerText.Trim()) + " "); 
      } 
      return sb.ToString(); 
     } 

提取文本而你需要HtmlAgilityPack


要移除BR標籤:

var str = Convert.ToString(GetCurrentColumnValue("Description")); 
Regex.Replace(str, @"</?\s?br\s?/?>", System.Environment.NewLine, RegexOptions.IgnoreCase); 
+1

感謝您的幫助 – user710502 2012-02-20 23:24:43