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
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)
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