Home > Software design >  PowerShell Get-Content do not display currency symbol euro (€), pound (£)
PowerShell Get-Content do not display currency symbol euro (€), pound (£)

Time:09-28

I read a csv file that contains currency symbol : us dollar ($), british pound (£) and euro (€). Here a short extract:

337;European €;NULL;
426;British £;NULL;
337;Americain $;NULL;

I use a powershell command to replace the "NULL" literal string in the file by an empty string :

(Get-Content %OutputFile%) -replace 'NULL', '' | Out-File -encoding unicode %OutputFile%

But the Get-Content don't correctly read the currencies symbols and return this :

337;ODEYEUREU;hf;Odey European €;;
426;INFLECGB;hf;Inflection Point C £;;
337;ODEYEUREU;hf;Odey European $;;

If the dollar is OK, the pound is prefixed by an expected character and the euro symbol is not display.

What encoding to use to handle all currency symbols (that I can specify in a inline command) ?

CodePudding user response:

You have to specify UTF8 encoding on both the Get-Content side and the Out-File side otherwise it might infer (guess) that you are trying to read in ASCII content. Otherwise the Out-File will take the mis-encoded content and output it "wrong". Try this:

(Get-Content %OutputFile% -Encoding UTF8) -replace 'NULL', '' | Out-File -Encoding UTF8 %OutputFile%
  • Related