Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

PowerShell Convert String Into Array

Posted on 2013-05-21
3
Medium Priority
?
656 Views
Last Modified: 2013-05-21
I have given up! I have a string with a semicolon ; as the delimiter - how do I use that to turn it into an array?

$var = One; Two; Three

What I have:
echo $var =
One; Two; Three

What I want:
echo $var =
One;
Two;
Three
0
Comment
Question by:brendan-amex
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 11

Accepted Solution

by:
apathy42 earned 2000 total points
ID: 39186022
$var.split(";") will turn it into the array.
0
 

Author Closing Comment

by:brendan-amex
ID: 39186027
Good quick answer. Thank you!
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 39186029
You really want the semicolon as part of the output? And what about the trailing (or leading) space? .Split or -split will both remove the delimiter. The result is
One
.Two
.Three

Open in new window

where the dot represents a space. We can use -split to have a two-char delimiter:
PS> "One; Two; Three" -split "; "
One
Two
Three

Open in new window

The .Split method is not able to do that, it accepts only arrays of single delimiting chars, which are then used separately.
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Fine Tune your automatic Updates for Ubuntu / Debian
In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the adminiā€¦
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question