How do I convert an array object to a string in PowerShell?

前端 未结 6 1623
执念已碎
执念已碎 2020-12-07 08:45

How can I convert an array object to string?

I tried:

$a = \"This\", \"Is\", \"a\", \"cat\"
[system.String]::J         


        
6条回答
  •  一生所求
    2020-12-07 09:11

    You could specify type like this:

    [string[]] $a = "This", "Is", "a", "cat"
    

    Checking the type:

    $a.GetType()
    

    Confirms:

        IsPublic IsSerial Name                                     BaseType
        -------- -------- ----                                     --------
        True     True     String[]                                 System.Array
    

    Outputting $a:

    PS C:\> $a 
    This 
    Is 
    a 
    cat
    

提交回复
热议问题