Powershell Array for Quotes Separated Comma String

I have an array that I need to output to a comma-separated string, but I also need quotation marks "". Here is what I have.

$myArray = "file1.csv","file2.csv" $a = ($myArray -join ",") $a 

Exit for $a ends

 file1.csv,file2.csv 

My desired result

 "file1.csv","file2.csv" 

How can i do this?

+5
source share
2 answers

Here you go:

 [array]$myArray = '"file1.csv"','"file2.csv"' [string]$a = $null $a = $myArray -join "," $a 

Output:

 "file1.csv","file2.csv" 

You just need to get out. " So you can do this by laying around it."

+9
source

I know this thread is outdated, but here are other solutions

 $myArray = "file1.csv","file2.csv" # Solution with single quote $a = "'$($myArray -join "','")'" $a # Result = 'file1.csv','file2.csv' # Solution with double quotes $b = '"{0}"' -f ($myArray -join '","') $b # Result = "file1.csv","file2.csv" 
+3
source

All Articles