1

I have got a csv with ";" delimiters which i imported with import-csv -delimiter ';' having done that i get an array with 3 Rows (class name name2) now the problem is: i need to remove "umlauts" from the array I already tried it like that

$csv1 = Import-Csv $PSScriptRoot\csvfile.csv -Delimiter ';'
$csv1.name2 = $csv1.Familienname -ireplace 'ä', 'ae'
$csv1.name2

to no avail, the output still remains the same (i.e ä stays ä and is not replaced by ae)

another idea I had was to write a loop that replaces the umlauts but I cant wrap my head around how to do that: could i do it somewhat like that

foreach ( ä,ö,ü in $csv1.name2) 
{ replace with a,oe,ue}

I would already be very thankful for just some links that get me in the right direction.

vogelspinne24
  • 55
  • 1
  • 9
  • It's better to replace in the source file: `(gc file.csv -raw) -replace 'ä', 'ae' | ConvertFrom-Csv` – wOxxOm Jun 05 '17 at 18:24
  • Possible duplicate of [How remove accents in PowerShell?](https://stackoverflow.com/questions/7836670/how-remove-accents-in-powershell) – Bacon Bits Jun 05 '17 at 18:27
  • hi! that sounds good, can i add more umlauts to that? like (gc file.csv -raw) -replace 'ä', 'ae'; 'ö', 'oe' | ConvertFrom-Csv – vogelspinne24 Jun 05 '17 at 18:28
  • 1
    You can daisy chain `-replace`, so `(gc file.csv -raw) -replace 'ä', 'ae' -replace 'ö', 'oe' | ConvertFrom-Csv -del ';'` – TheMadTechnician Jun 05 '17 at 18:35
  • @TheMadTechnician thanks! but what does the -del stand for? nvm figured it out its the alias for delimiter? – vogelspinne24 Jun 05 '17 at 18:37
  • Yeah, for parameters you only have to actually use enough of it to make it unique, so since there are no other parameters that start with `-del` PowerShell assumes that it must be short for `-Delimiter`. – TheMadTechnician Jun 05 '17 at 18:40
  • alright thanks to everyone if somebody has the same problem: here is the apparent solution $csv = (gc $PSScriptRoot\csvfile.csv -raw) -ireplace 'ä', 'ae' -ireplace 'ö', 'oe' -ireplace 'ü', 'ue' -ireplace 'ß', 'ss' | ConvertFrom-Csv -Delimiter ';' is there something like a powershell chat where i can ask small stupid questions like that? – vogelspinne24 Jun 05 '17 at 18:41
  • @vogelspinne24 post it as an answer (self-answers are perfectly fine), not a comment – Mathias R. Jessen Jun 05 '17 at 19:45

1 Answers1

1

Here is the solution that worked for me:

$csv = (gc $PSScriptRoot\csvfile.csv -raw) -ireplace 'ä', 'ae' -ireplace 'ö', 'oe' -ireplace 'ü', 'ue' -ireplace 'ß', 'ss' | ConvertFrom-Csv -Delimiter ';' 
mklement0
  • 382,024
  • 64
  • 607
  • 775
vogelspinne24
  • 55
  • 1
  • 9