4

I try to

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

and it gives me

Unrecognized token in source text.

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

YOU
  • 120,166
  • 34
  • 186
  • 219
Filburt
  • 17,626
  • 12
  • 64
  • 115

2 Answers2

6

Remove the @ char - it is not here-string.

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

Added after S.Mark's answer:

I'll add because S.Mark already posted answer, that can be accepted, that here-strings begin with @. Try to google them. And - it's somewhat different to C#. You don't escape with \, but with backtick. So probably the string should be something like "`u00A0", but I'm not sure...

Solution

After some hanging around stack overflow, I found Shay's answer that probably is what you wanted.

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

or maybe

$arr -join [char]0x00A0

Shay's answer how to escape unicode character.

Community
  • 1
  • 1
stej
  • 28,745
  • 11
  • 71
  • 104
  • Yes, that's exactly what i was looking for but i got stuck casting the unicode to char. – Filburt Jan 29 '10 at 14:37
  • 3
    In case it isn't obvious from the post (which guesses more than anything else): PowerShell has no Unicode escape method inside of strings, so yes, the only useful way to do this is by casting an integer to a `char`. – Joey Jan 29 '10 at 15:19
2

You would not need @ before "\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
YOU
  • 120,166
  • 34
  • 186
  • 219
  • This just explains the error but didn't help me to join with a non-breaking space, so stej gets marker. Thanks for your support nonetheless. – Filburt Jan 29 '10 at 14:41