2
(Get-Content -Path $filePath) -creplace ${find}, $replace | Add-Content -Path $tempFilePath 

If $find and $replace contains below values it's not replacing it

ç c
à a
é e

Please help

Shayki Abramczyk
  • 36,824
  • 16
  • 89
  • 114
  • 1
    Does this answer your question? [Converting Unicode string to ASCII](https://stackoverflow.com/questions/46658267/converting-unicode-string-to-ascii) or [Replacing characters with diacritics in a string](https://stackoverflow.com/q/43493484/1701026) – iRon Jul 05 '20 at 11:13
  • Works for me: `'ç' -replace 'ç','c'` – js2010 Jul 05 '20 at 14:25

2 Answers2

2

You need to -Encoding UTF8 to the Get-Content method, for reading the special characters correctly:

(Get-Content -Path $filePath -Encoding UTF8) -creplace ${find}, $replace | Add-Content -Path $tempFilePath 
Shayki Abramczyk
  • 36,824
  • 16
  • 89
  • 114
2

If by characters like ü you mean Diacritics you can use this:

function Replace-Diacritics {
    Param(
        [Parameter(Mandatory = $true, ValueFromPipeline = $true)]
        [string] $Text
    )
    ($Text.Normalize([Text.NormalizationForm]::FormD).ToCharArray() | 
     Where-Object {[Globalization.CharUnicodeInfo]::GetUnicodeCategory($_) -ne 
                   [Globalization.UnicodeCategory]::NonSpacingMark }) -join ''
}

# you can experiment with the `-Encoding` parameter
Get-Content -Path 'D:\Test\TheFile.txt' -Encoding UTF8 -Raw | Replace-Diacritics | Set-Content -Path 'D:\Test\TheNewFile.txt'
Theo
  • 57,719
  • 8
  • 24
  • 41