什么';这是修复/替换从C#中的源代码中抓取的xhtml实体的最佳方法

本文关键字:源代码 抓取 xhtml 方法 最佳 实体 替换 什么 | 更新日期: 2023-09-27 17:58:08

本质上,我正在获取包含&>等实体的源代码,我想用&和>。简单的字符串替换将是完全详尽的,因为源代码中可能出现数百个实体。有没有内置或标准的方法可以做到这一点,这样我就不必键入一百行字符串替换了?

谢谢!:)

什么';这是修复/替换从C#中的源代码中抓取的xhtml实体的最佳方法

也许WebUtility.HtmlDecode方法就是您想要的

本文给出了一个使用Powershell将其称为的例子

HTMLDecode Sample - Using PowerShell
<#
.SYNOPSIS
    This script encodes and decodes an HTML String
.DESCRIPTION
    This script used 
.NOTES
    File Name  : Show-HtmlCoding.ps1
    Author     : Thomas Lee - tfl@psp.co.uk
    Requires   : PowerShell Version 2.0
.LINK
    This script posted to:
        http://www.pshscripts.blogspot.com
    MSDN sample posted tot:
        http://msdn.microsoft.com/en-us/library/ee388364.aspx
.EXAMPLE
    PSH [C:'foo]: .'Show-HtmlCoding.ps1
    Original String: <this is a string123> & so is this one??
    Encoded String : &lt;this is a string123&gt; &amp; so is this one??
    Decoded String : <this is a string123> & so is this one??
    Original string = Decoded string?: True   
#>
# Create string to encode/decode
$Str = "<this is a string123> & so is this one??"
# Encode String
$Encstr = [System.Net.WebUtility]::HtmlEncode($str)
# Decode String
$Decstr = [System.Net.WebUtility]::HtmlDecode($EncStr)
# Display strings
"Original String: {0}" -f $Str
"Encoded String : {0}" -f $Encstr
"Decoded String : {0}" -f $Decstr
$eq = ($str -eq $Decstr)
"Original string = Decoded string?: {0}" -f $eq 

我会使用sed控制台命令并为此编写一个小脚本。试着用谷歌搜索sed单行。我打赌你一定喜欢。