Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Splitting a string into separate variables

I have a string, which I have split using the code $CreateDT.Split(" "). I now want to manipulate two separate strings in different ways. How can I separate these into two variables?

like image 615
davetherave Avatar asked Jun 03 '15 10:06

davetherave


People also ask

How do I split a string into another variable?

Python split() method is used to split the string into chunks, and it accepts one argument called separator. A separator can be any character or a symbol. If no separators are defined, then it will split the given string and whitespace will be used by default.

How do you split a string into two variables in PowerShell?

To do this, make the desired character or string to split around the second argument to the split function, by writing s. split(",") or s -split "," to split on a comma, for example. Whatever character you choose to give to PowerShell as delimiter, or separator, will be omitted from all the result strings.

How do you split variables in Python?

To split string variables at each whitespace, we can use the split() function with no arguments. The syntax for split() function is split(separator, maxsplit) where the separator specifies the character at which the string should be split. maxsplit specifies the number of times the string has to be split.


1 Answers

Like this?

$string = 'FirstPart SecondPart' $a,$b = $string.split(' ') $a $b 
like image 92
mjolinor Avatar answered Sep 25 '22 01:09

mjolinor