Quantcast
Channel: /r/powershell – How to Code .NET
Viewing all articles
Browse latest Browse all 8793

help iterating over a string

$
0
0

This works perfectly in ISE, but not a normal PS session – even as administrator.

$msg = "TEST" $msg = $msg.toCharArray() foreach ($letter in $msg) { write-host "This is the letter " $letter } 

It works as designed in ISE, but not in PS session, which is backward to what I normally experience. lol.

Here’s the output: *This is the letter T E S T *

It appears that the regular session isn’t treating the character array correctly. If I display the contents of $msg, after converting to a character array, I get T E S T , instead of the individual characters:

T
E
S
T

Any help appreciated.

edit: formatting

submitted by /u/MericanCheese
[link] [comments]

The post help iterating over a string appeared first on How to Code .NET.


Viewing all articles
Browse latest Browse all 8793

Trending Articles