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
Post a Comment