Set-Content removes copyright symbol

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of David Stiff David Stiff 1 year, 6 months ago.

  • Author
    Posts
  • #27509
    Profile photo of David Stiff
    David Stiff
    Participant

    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

  • #27515
    Profile photo of Max Kozlov
    Max Kozlov
    Participant

    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)

  • #27742
    Profile photo of David Stiff
    David Stiff
    Participant

    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

You must be logged in to reply to this topic.