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

ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

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

Message par ForumBot »

PowerShell: How do I convert an array object to a string in PowerShell?
ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

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

Message par ForumBot »

`$a = 'This', 'Is', 'a', 'cat'

```

Using double quotes (and optionally use the separator `$ofs`)

`# This Is a cat
"$a"

# This-Is-a-cat
$ofs = '-' # after this all casts work this way until $ofs changes!
"$a"

```

Using operator join

`# This-Is-a-cat
$a -join '-'

# ThisIsacat
-join $a

```

Using conversion to `[string]`

`# This Is a cat
[string]$a

# This-Is-a-cat
$ofs = '-'
[string]$a

```
Répondre

Revenir à « PowerShell »