Quantcast
Channel: Hey, Scripting Guy! Blog
Viewing all articles
Browse latest Browse all 3333

PowerTip: Convert Character Array to String

$
0
0

Summary: Easily convert a character array to a string in Windows PowerShell.

Hey, Scripting Guy! Question How can I use Windows PowerShell to convert data that is returning as an array of characters
          instead of as a single string?

Hey, Scripting Guy! Answer Use the unary operator, and pass the array. In the following example, the first command returns an
          array of characters, and the next the unary operator converts the character array to a single string:

PS C:\> $a = (get-module -l)[0].Path | split-path -Parent

PS C:\> $a[0]

C

PS C:\> $b = (,$a)

PS C:\> $b[0]

C:\Users\ed\Documents\WindowsPowerShell\Modules\ConversionModule

PS C:\>


Viewing all articles
Browse latest Browse all 3333

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>