如何用UTF-8字符替换ANSI字符并以UTF-8格式保存文档?

问题描述:

我尝试运行此命令:

(Get-Content c:\example.srt).replace('æ', 'ć') | Set-Content c:\example.srt

但是它仅将字符æ替换为ANSI c.

But it only replaces the character æ with ANSI c.

我还希望能够同时替换多个字符.

I'd also like to be able to replace more than 1 character at the time.

您可以尝试一下.它将文件从 Windows-1252 转换为

You can give this a go. It converts a file from Windows-1252 to UTF-8.

$ansi = [System.Text.Encoding]::GetEncoding(1252)

Get-Content -Encoding $ansi "c:\example.srt" | Out-File -Encoding UTF-8 "c:\example.srt"