Issue
I have an array that I need to output to a comma separated string but I also need quotes “”. Here is what I have.
$myArray = "file1.csv","file2.csv"
$a = ($myArray -join ",")
$a
The output for
$a
ends up
file1.csv,file2.csv
My desired output is
"file1.csv","file2.csv"
How can I accomplish this?
Solution
Here you go:
[array]$myArray = '"file1.csv"','"file2.csv"'
[string]$a = $null
$a = $myArray -join ","
$a
Output:
"file1.csv","file2.csv"
You just have to get a way to escape the "
. So, you can do it by putting around it '
.
Answered By – Syphirint
Answer Checked By – Mary Flores (BugsFixing Volunteer)