|
ms
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Read Stream Until Bytes Hit?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 -- ----------------------- Beste Grüsse / Best regards / Votre bien devoue Kerem Gümrükcü Microsoft Live Space: http://kerem-g.spaces.live.com/ Latest Open-Source Projects: http://entwicklung.junetz.de ----------------------- "This reply is provided as is, without warranty express or implied." There was no indication from the OP that the file had any new lines in
it. -- Show quote- Nicholas Paldino [.NET/C# MVP] - mvp@spam.guard.caspershouse.com "Kerem Gümrükcü" <kareem***@hotmail.com> wrote in message news:ORLoXErMIHA.2208@TK2MSFTNGP06.phx.gbl... > Hi, > > what about reading the File Line-By-line and > doing a String.Split() on it? > > > Regards > > Kerem > > -- > ----------------------- > Beste Grüsse / Best regards / Votre bien devoue > Kerem Gümrükcü > Microsoft Live Space: http://kerem-g.spaces.live.com/ > Latest Open-Source Projects: http://entwicklung.junetz.de > ----------------------- > "This reply is provided as is, without warranty express or implied." > 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 -- ----------------------- Beste Grüsse / Best regards / Votre bien devoue Kerem Gümrükcü Microsoft Live Space: http://kerem-g.spaces.live.com/ Latest Open-Source Projects: http://entwicklung.junetz.de ----------------------- "This reply is provided as is, without warranty express or implied." 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. -- Show quote- Nicholas Paldino [.NET/C# MVP] - mvp@spam.guard.caspershouse.com "Kerem Gümrükcü" <kareem***@hotmail.com> wrote in message news:exj%23tRrMIHA.3940@TK2MSFTNGP05.phx.gbl... > 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 > > -- > ----------------------- > Beste Grüsse / Best regards / Votre bien devoue > Kerem Gümrükcü > Microsoft Live Space: http://kerem-g.spaces.live.com/ > Latest Open-Source Projects: http://entwicklung.junetz.de > ----------------------- > "This reply is provided as is, without warranty express or implied." > On 2007-11-29 10:29:26 -0800, "Nicholas Paldino [.NET/C# MVP]"
<mvp@spam.guard.caspershouse.com> said: > Even if there was an end of line character in the stream, the OP The OP also wrote that he was reading bytes using a StreamReader, which > 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. 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 Hi Nicholas,
>Even if there was an end of line character in the stream, the OP specified Ok, you are right,..just asking, maybe this will be sufficient for him. He>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. 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 -- ----------------------- Beste Grüsse / Best regards / Votre bien devoue Kerem Gümrükcü Microsoft Live Space: http://kerem-g.spaces.live.com/ Latest Open-Source Projects: http://entwicklung.junetz.de ----------------------- "This reply is provided as is, without warranty express or implied." 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. -- Show quote- Nicholas Paldino [.NET/C# MVP] - mvp@spam.guard.caspershouse.com "coconet" <coconet@community.nospam> wrote in message news:lfutk3do902jhjlggnm0lclbsuoa55hg1i@4ax.com... >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. > > Nicholas Paldino [.NET/C# MVP] <mvp@spam.guard.caspershouse.com> wrote:
> If you are using a StreamReader, then you are reading characters, not And if he's reading bytes then he'll never hit ';' as that's a > bytes. character :) Time to understand the difference between the two, I reckon... -- Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet World class .NET training in the UK: http://iterativetraining.co.uk |
|||||||||||||||||||||||