473,385 Members | 2,210 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

a quick (and easy) question

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.
Nov 17 '05 #1
5 1169
I wudnt say no in conisdering
readSwitches.ReadToEnd()
cud possibly return null which causes a run time exception.

however (i wud like to do it like the following)
string str = readSwitches.ReadToEnd();
if (str == null) {
//report error or do something
//return ???
}
string[] allSwitchValues = str.Split('|');
regards
Nov 17 '05 #2
Ashura <As****@discussions.microsoft.com> wrote:
I wudnt say no in conisdering
readSwitches.ReadToEnd()
cud possibly return null which causes a run time exception.

however (i wud like to do it like the following)
string str = readSwitches.ReadToEnd();
if (str == null) {
//report error or do something
//return ???
}
string[] allSwitchValues = str.Split('|');


I don't think StreamReader *can* return null, actually. From the
documentation:

<quote>
If the current position is at the end of the stream, returns the empty
string("").
</quote>

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 17 '05 #3
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?)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 17 '05 #4
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?
Nov 17 '05 #5
John Salerno <jo******@NOSPAMgmail.com> wrote:
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?


No. Putting it into two lines makes no odds at all. You could read the
file a line at a time, of course - or replace all the "\r\n" with ""
after reading it all.
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?


Just ignore the last returned element.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.