Read Stream Until Bytes Hit?

  • Thread starter Thread starter coconet
  • Start date Start date
C

coconet

I am trying to use a StreamReader to read consecutive bytes into a
byte array until a ";" is hit, then store everything read up until
that point into a new byte array.

I have a semicolon-delimited file that I am trying to read and parse
using StreamReader and byte arrays.

Thanks.
 
Hi,

what about reading the File Line-By-line and
doing a String.Split() on it?


Regards

Kerem

--
 
There was no indication from the OP that the file had any new lines in
it.
 
If you are using a StreamReader, then you are reading characters, not
bytes. The StreamReader will read the bytes from the underlying stream and
then use an encoding to translate the bytes into characters according to
that encoding's definition.

If you have your StreamReader, then you will want to call Read in a
loop, taking the return value and checking against the semi-colon character
(';'), or -1 (in case you run to the end of the stream). That's pretty much
the only way to do it.
 
Hi Nicholas,
There was no indication from the OP that the file had any new lines in it.

Maybe there is and if so, this would be a good way in doing the split.
Maybe!
Thats why the "?" finished my Line. If not with EOL, then reading block by
block is the way...


Regards

Kerem

--
 
Even if there was an end of line character in the stream, the OP
specified that they wanted to read up to, not past the semi colon character.
If you read to EOL, then you would read past the semi-colons in the string,
if there were any.
 
Even if there was an end of line character in the stream, the OP
specified that they wanted to read up to, not past the semi colon character.
If you read to EOL, then you would read past the semi-colons in the string,
if there were any.

The OP also wrote that he was reading bytes using a StreamReader, which
doesn't make sense.

The fact is, the OP didn't write a very good question. There are a
number of ambiguities and inconsistencies. It would be better if he
could simply clarify what he's actually doing, but barring that it
seems like Kerem's suggestion certainly _could_ help.

Pete
 
Nicholas Paldino said:
If you are using a StreamReader, then you are reading characters, not
bytes.

And if he's reading bytes then he'll never hit ';' as that's a
character :)

Time to understand the difference between the two, I reckon...
 
Hi Nicholas,
Even if there was an end of line character in the stream, the OP specified
that they wanted to read up to, not past the semi colon character. If you
read to EOL, then you would read past the semi-colons in the string, if
there were any.

Ok, you are right,..just asking, maybe this will be sufficient for him. He
can tell us if is an option for him or not,...

Good, ok then we should ask the OP whether he can give us some
short example of how the file does look like so that we can find
a appropriate solution for him,...instead of telling us what he told
or not. By the way his question is not really clear and reading this
with a StreamReader he wont find a ";". We should first talk about that!

So dear OP, can you give us a short example how your file does look like?

Maybe so

askdjhad;asdsdsda;asdasdas;

or that way:

afwwerwe....;aeaw ;.a.....er...rgter:;.- ; sefadfad ;

or something differenent?

Regards

Kerem

--
 
Hi Coconet ,

Have you reviewed all the replies to you? Do they make sense to you? If you
still need any help, please feel free to feedback, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top