powershell - Joining back a splitted variable -


$(((get-adrootdse).defaultnamingcontext).split(",dc=")) 

this gives following output. (literal output)

ps c:\users\administrator> $((get-adrootdse).defaultnamingcontext).split(",dc=")    contoso    com 

i contoso.com result. splitting variable wasn't issue. however, how join 2 parts again? i've found examples on how join , split, not on how 'rejoin' after split method.

you can use -join operator join strings:

ps> "a,s,d,f".split(",") -join "" asdf 

the value after -join operator character or text want join with.

alternatively can use more explicit .net method string.join:

ps> [system.string]::join("", "a,s,d,f".split(",")) asdf 

the first argument join character, second list want join.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -