Jon Skeet [C# MVP] wrote:
John Salerno <jo******@NOSPAMgmail.com> wrote:
Is this valid:
string[] allSwitchValues = readSwitches.ReadToEnd().Split('|');
I have no way to test it just yet (although it didn't seem to create
compile errors). Originally I had it divided into two variables on two
lines, but it seems like I only need the one variable, assuming I can't
combine the ReadToEnd and Split methods like so.
Yes, you can do the above - that should be fine, at least in terms of
syntax. (Are you happy for it not to do anything with line breaks?)
Ah, what a smart question. I did notice that every 20th character in the
array was stored as "\r\n1" (or "\r\n0") and I thought maybe this was
just a result of having used a linebreak. So I put it all on one line to
fix this. If I go back to the original way of having this code on two
lines with two variables, would it not do this with the linebreaks?
Also, I noticed that because the file ended with a "|", the array had as
the last character an empty string, I guess because it was reading what
was to the right of that pipe character (which was nothing), so I just
took out that last pipe. Is there a way to fix that too, while leaving
in the pipe character?