Author Posts

July 14, 2015 at 11:33 am

Hello,

I am writing a search-and-replace function. The essentials are:


$encoding = Get-FileEncoding $filename
$text = Get-Content -Path $filename -Raw
$text -replace $searchText, $replaceText | Set-Content -Path $filename -Encoding $encoding

The code is working but a copyright symbol ©, ASCII 184, is being replaced by a question mark.

Any ideas on this?

Thanks,
Dave

July 14, 2015 at 1:41 pm

which Encoding you get in $encoding ?
if this function correct, try to use Get-Content -Encoding $encoding
you also can try to save your file in unicode to make sure that copyright still inside.

btw in arial font (C) sign code is A9 (169)

July 21, 2015 at 12:20 pm

Hi Max,

sorry for the late reply. Using Unicode does preserve the copyright symbol. Default preserves it as well and doesn't change the file encoding so I will use that.

Previously the Get-FileEncoding was returning ASCII (which it defaults to if it cannot match any other format).

Thanks,
Dave