在powershell中替换"智能引号"

Sco*_*ein 4 unicode powershell

我发现自己有点难过一个简单的问题.我试图从一堆文本文件中删除花哨的引用.我有以下脚本,我正在尝试一些不同的替换方法,但没有结果.

这是一个从github下载数据并尝试转换的示例.

$srcUrl="https://raw.github.com/gist/1129778/d4d899088ce7da19c12d822a711ab24e457c023f/gistfile1.txt"
$wc = New-Object net.WebClient
$wc.DownloadFile($srcUrl,"foo.txt")
$fancySingleQuotes = "[" + [string]::Join("",[char[]](0x2019, 0x2018)) + "]"

$c = Get-Content "foo.txt"
$c | % { `
        $_ = $_.Replace("’","'")
        $_ = $_.Replace("`“","`"")
        $_.Replace("`”","`"")       
    } `
    |  Set-Content "foo2.txt"
Run Code Online (Sandbox Code Playgroud)

有什么办法可以解决这个问题?

E.Z*_*art 5

更新:修正了我的答案(manojlds的评论是正确的,$ _的东西是红鲱鱼).这是一个有效的版本,我已经更新它以包含您的测试代码:

    $srcUrl="https://raw.github.com/gist/1129778/d4d899088ce7da19c12d822a711ab24e457c023f/gistfile1.txt"
    $wc = New-Object net.WebClient
    $wc.DownloadFile($srcUrl,"C:\Users\hartez\SO6968270\foo.txt")

    $fancySingleQuotes = "[\u2019\u2018]" 
    $fancyDoubleQuotes = "[\u201C\u201D]" 

    $c = Get-Content "foo.txt" -Encoding UTF8

    $c | % { `
        $_ = [regex]::Replace($_, $fancySingleQuotes, "'")   
        [regex]::Replace($_, $fancyDoubleQuotes, '"')     
    } `
    |  Set-Content "foo2.txt"
Run Code Online (Sandbox Code Playgroud)

manojlds版本不适合你的原因是你从github获得的文件的编码与正则表达式中的Unicode字符不兼容.以UTF-8读取它可以解决问题.