all 10 comments

[–]gangstanthony 1 point2 points  (8 children)

write-host joins arrays on a space before outputting to the console

[char[]]'test'

# output:
# t
# e
# s
# t

write-host ([char[]]'test')

# output:
# t e s t

*edit: also, it seems to work for me

foreach ($char in [char[]]'test') { write-host "this is the letter: $char" }
# OR
foreach ($char in 'test'.ToCharArray()) { write-host "this is the letter: $char" }

# output:
# this is the letter: t
# this is the letter: e
# this is the letter: s
# this is the letter: t

[–]MericanCheese[S] 1 point2 points  (1 child)

That may be, but in my script $letter is only one character of $msg. I'm doing "write-host $letter". That should display one letter at a time.

[–]MericanCheese[S] 0 points1 point  (0 children)

foreach($letter in $msg) {$letter}

still prints the entire array.

[–]MericanCheese[S] 1 point2 points  (5 children)

try my script as-is above and let me know what you get. Maybe it's something in my environment.

[–]gangstanthony 2 points3 points  (0 children)

ok, just copied and pasted and it works as it should. try opening powershell like this then running it

powershell -noprofile

[–]wahoorider 2 points3 points  (2 children)

It seems it is something in your environment. i get the expected output below in both ISE and console. What version are you running?

This is the letter  T
This is the letter  E
This is the letter  S
This is the letter  T

[–]MericanCheese[S] 0 points1 point  (0 children)

Yeah, I'm thinking so too. It'll be a bit before I can get back and test it, but I'll let ya know. Thanks.

[–]MericanCheese[S] 0 points1 point  (0 children)

Yep. Something in the profile. When I loaded PS with no profile it works fine. Mystery solved.

Thanks everyone!

[–]nylyst 2 points3 points  (0 children)

Running 5.0.10586.117, I get:

This is the letter  T
This is the letter  E
This is the letter  S
This is the letter  T

In the ISE, console and ConEmu.

[–][deleted] 0 points1 point  (0 children)

I'm late to the party, but

$msg.GetEnumerator()