简体   繁体   中英

How to replace ANSI characters with UTF-8 characters and save the document in UTF-8 format?

I tried running this:

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

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.

You can do like this:

Replace them in the character group.Put the symbols in the character group.

Get-Content c:\example.srt |% {$_ -replace "[æ\._\.*]", "ć"}

It will replace æ , _ , * with ć .

like:

Get-Date -Format G | foreach {$_ -replace "[:\./]", "_"}

Hope it helps.

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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM