# Replace letter " to "" in export-csv powershell

**URL:** <https://forums.powershell.org/t/replace-letter-to-in-export-csv-powershell/8988>\
**Category:** PowerShell Help\
**Created:** [July 10, 2017, 12:54pm UTC](https://forums.powershell.org/t/replace-letter-to-in-export-csv-powershell/8988 "2017-07-10T12:54:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![rsar](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/rsar/32/463_2.png) [@rsar](https://forums.powershell.org/u/rsar)\
**Post date:** [July 10, 2017, 12:54pm UTC](https://forums.powershell.org/t/replace-letter-to-in-export-csv-powershell/8988/1 "2017-07-10T12:54:34Z")

</div>

Hi All,  
I am trying to work on a requirement. When there is a " will come in a field in csv it should convert to “”.

Could you please help making that powershell command. I have written below so far.

Input Output  
“sample” ““sample””  
"Samp"le "“samp"le”

Import-Csv “C:\Users\RSar-2\Desktop\Accutrac.csv” -Delimiter ‘~’ | where {$_.USER\_NAME -ne “---------”} | ForEach-Object {  
if ($_.Project\_Desc -eq ‘VERTIGO’) {  
$_.Project\_Desc = ‘“VERTIGO”’  
}  
$_ | Export-Csv -Path “C:\Users\RSar-2\Desktop$($\_.USER\_NAME).csv” -NoTypeInformation -Append -Delimiter ‘~’  
}

---

<div class="post-metadata">

**Author:** ![jarkko](https://avatars.discourse-cdn.com/v4/letter/j/eb8c5e/32.png) [@jarkko](https://forums.powershell.org/u/jarkko)\
**Post date:** [July 10, 2017, 1:08pm UTC](https://forums.powershell.org/t/replace-letter-to-in-export-csv-powershell/8988/2 "2017-07-10T13:08:14Z")

</div>

Hi

How about if you export ‘"’ + $\_ + ‘"’? Dirty but works.

```
'"yeah"','"wohoo"' | ForEach-object {

    '"' + $_ + '"'

}
""yeah""
""wohoo""
```

Tried also following:

```
'"yeah"','"wohoo"' | ForEach-object {

    $($_).insert(0,'"').insert(($_.length)+1,'"')

}
""yeah""
""wohoo""
```

Regards

Jarkko

---

<div class="post-metadata">

**Author:** ![random-commandline](https://avatars.discourse-cdn.com/v4/letter/r/e56c9b/32.png) [@random-commandline](https://forums.powershell.org/u/random-commandline)\
**Post date:** [July 10, 2017, 7:50pm UTC](https://forums.powershell.org/t/replace-letter-to-in-export-csv-powershell/8988/3 "2017-07-10T19:50:07Z")

</div>

Use the -replace operator.

```
Import-Csv "C:\Users\RSar-2\Desktop\Accutrac.csv" -Delimiter '~' | 
where {$_.USER_NAME -ne "———"} | ForEach-Object {$_ -replace '"','""'} |
Export-Csv -Path "C:\Users\RSar-2\Desktop\$($_.USER_NAME).csv" -NoTypeInformation -Append -Delimiter '~'
```

---

<div class="post-metadata">

**Author:** ![jarkko](https://avatars.discourse-cdn.com/v4/letter/j/eb8c5e/32.png) [@jarkko](https://forums.powershell.org/u/jarkko)\
**Post date:** [July 10, 2017, 11:52pm UTC](https://forums.powershell.org/t/replace-letter-to-in-export-csv-powershell/8988/4 "2017-07-10T23:52:15Z")

</div>

Hi

Isn’t that also replace the quotamarks inside the string that do not need to be doubled?

Input Output  
“sample” ““sample””  
"Samp"le "“samp"le”

Regards

Jarkko

---

<div class="post-metadata">

**Author:** ![rsar](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/rsar/32/463_2.png) [@rsar](https://forums.powershell.org/u/rsar)\
**Post date:** [July 11, 2017, 11:25am UTC](https://forums.powershell.org/t/replace-letter-to-in-export-csv-powershell/8988/5 "2017-07-11T11:25:03Z")

</div>

Now I am replacing " to some other characters and then converting them back to " after new csv is prepared. That helped my cause.

Get-ChildItem ‘E:\test\*.csv’ -Recurse | ForEach {  
(Get-Content $\_ | ForEach { $\_ -replace ‘"’, ‘#’ }) |  
Set-Content $\_  
}

Get-ChildItem ‘E:\test\*.csv’ -Recurse | ForEach {  
(Get-Content $\_ | ForEach { $\_ -replace ‘#’, ‘"’ }) |  
Set-Content $\_  
}

Thanks for your inputs Jarkko!! Apreciated!

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:37pm UTC](https://forums.powershell.org/t/replace-letter-to-in-export-csv-powershell/8988/6 "2024-05-16T20:37:53Z")

</div>

Closed on May 16, 2024, 8:37pm UTC


