if I save it as a txt file and point get-content at that text file, I get an array with 3 rows.
what’s the easiest way to get that same array if I just want to paste that text list directly into the ISE instead of saving it into a text file and pointing get-content at that text file?
thank you Richard. the @‘…’@ syntax was what I was missing. I was bringing the list in as a pure “string”:
$x = “item1
item2
item3”
and then splitting it. your way is much cleaner. with the added “copying and pasting ease/laziness” benefit of not having to have the first and last items in the list on the same line as the quotation marks.
i’m back. if I paste Richard’s whole script into the ISE, and then add this to the bottom
$x[0].Length
I get 5. which is correct.
if I type item1, item2, item3 into the here-string, I also get 5.
but if I copy and paste
item1
item2
item3
from anywhere on this page into my here-string, the length turns into 6. even if I paste it into notepad first and then copy it from notepad into the ISE.
Hi John,
You never really asked a question, but I assume the question is why you are getting 6 instead of 5.
It is mostly likely that you are not accounting for the carriage return. Try doing the following instead to account for the carriage return as well as the line feed.
Curtis, I just pasted your whole script into ise, and $x.length came back as 1, and $x[0].length came back as 17.
if I use “`r|`n” as the split, then $x.length is correctly 3 and $x[0].length is correctly 5.
but again, if I paste
item1
item2
item3
into the here-string from notepad, $x.length becomes 5. so there are two extra elements in the array, which I can also see if I do $x | out-gridview (there are blank lines)
Curtis, you went back to only splitting it by the newline. not by newline and carriage return.
in any event, if I paste your new script from this site into my 5.1 ise, I get an array with a length of 3 and element 0 has a length of 5. no extra characters.
interestingly, if I copy out the three members of your here-string from my ISE and paste them into notepad, they appear on one line with no spaces:
item1item2item3
but if I then copy that out of notepad, and paste it in this thread, or into another ise window, they are stacked with carriage returns (or new lines, whichever it is).
item1
item2
item3
if I type my own into notepad:
item1
item2
item3
and then paste that into the here-string in your script in my ISE, I get the same results you got. array length 3, element 0 length 6 with an extra character 13 on the end.