Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/300.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
什么';修复/替换从C#源代码中获取的xhtml实体的最佳方法是什么?_C#_Xhtml - Fatal编程技术网

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

什么';修复/替换从C#源代码中获取的xhtml实体的最佳方法是什么?,c#,xhtml,C#,Xhtml,本质上,我获取的源代码包含&和>,我想分别用&和>。一个简单的字符串替换将是完全详尽的,因为源代码中可能会出现数百个实体。有没有一种内置的或标准的方法来实现这一点,这样我就不必键入一百行字符串替换 谢谢!:) 也许你正在寻找的就是这种方法 本文给出了一个使用Powershell调用它的示例 HTMLDecode Sample - Using PowerShell <# .SYNOPSIS This script encodes and decodes an HTML S

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

谢谢!:)

也许你正在寻找的就是这种方法

本文给出了一个使用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 
HTMLDecode示例-使用PowerShell
#创建要编码/解码的字符串
$Str=“&这一个也是吗??”
#编码字符串
$Encstr=[System.Net.WebUtility]::HtmlEncode($str)
#解码字符串
$Decstr=[System.Net.WebUtility]::HtmlDecode($EncStr)
#显示字符串
“原始字符串:{0}”-f$Str
“编码字符串:{0}”-f$Encstr
“解码字符串:{0}”-f$Decstr
$eq=($str-eq$Decstr)
“原始字符串=解码字符串?:{0}”-f$eq

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

我只是根据自己的需要修改了它,并推出了行System.Net.WebUtility.HtmlCode(输入),它工作得非常出色。感谢您的快速而有益的回复!:)