Attach a non-breaking space string in Powershell

I'm trying to

$arr = "one", "two" $test = [String]::Join(@"\u00A0", $arr) 

and he gives me

 Unrecognized token in source text. 

Is it because I have to specify it in utf-8 as 0xC2 0xA0 ?

+4
source share
2 answers

Remove @ char - there is no line here.

 [String]::Join("\u00A0", $arr) 

Added after S. Mark's answer:

I will add, because S.Mark has already posted an answer that you can accept that here the lines begin with @ . Try google them. And - this is slightly different from C #. You do not run away with \ , but with the return stroke. So probably the line should be something like "` u00A0 ", but I'm not sure ...

Decision

After some freezing, I found Shay's answer, which is probably what you wanted.

 [String]::Join([char]0x00A0, $arr) 

or maybe

 $arr -join [char]0x00A0 

Shay answer how to avoid the Unicode character.

+5
source

You donโ€™t need @ to "\ u00A0"

 PS > $arr = "one", "two" PS > $test = [String]::Join(@"\u00A0", $arr) Unrecognized token in source text. PS > $test = [String]::Join("\u00A0", $arr) PS > PS > $test one\u00A0two 
+2
source

Source: https://habr.com/ru/post/1299743/


All Articles