Welcome › Forums › General PowerShell Q&A › Set-Content removes copyright symbol
This topic contains 2 replies, has 2 voices, and was last updated by
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?
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)
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).
The topic ‘Set-Content removes copyright symbol’ is closed to new replies.