0

我对 regex 有点陌生,如果您能帮助我了解如何使用 regex 将转义字符替换回文字 html 字符串,我将不胜感激。我尝试使用 string.replace 并且它只替换了代码的某些部分而不是全部。

例如:string.replace("&lt;","<") ;//这有效,但仅在一行上,当它变成循环时,这是一个问题,对于熟悉代码的人来说,是的,这是一个 SP 博客代码,其中 SP 将 html 文字标记转换为转义字符。

<div class="ExternalClass2BF55814E98A409296EC90A2605D7D74">
  <div>&ltiframe src=&quot
    <a href=http://player.vimeo.com/video/32001208?portrait=0&ampampbadge=0>
            http://player.vimeo.com/video/32001208?portrait=0&ampampbadge=0
    </a>&quot;
    width=&quot;420&quot; height=&quot;281&quot; frameborder=&quot0&quot 
    webkitAllowFullScreen mozallowfullscreen allowFullScreen&gt&lt/iframe&gt; 
  </div>
</div>
4

1 回答 1

0

如果您的字符串是 HTML 编码的,您最好通过Server.HtmlDecode(). 这会将其转换回 HTML。

IE

    '' In VB
    Dim myHtml as String = Server.HtmlDecode(YourConcatonatedEncodedHTML)

    // in C#
    string myHtml = Server.HtmlDecode(YourConcatonatedEncodedHTML);
于 2012-12-14T16:15:49.047 回答