Read Stream Until Bytes Hit?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • coconet

    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.


  • Kerem Gümrükcü

    #2
    Re: Read Stream Until Bytes Hit?

    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."


    Comment

    • Nicholas Paldino [.NET/C# MVP]

      #3
      Re: Read Stream Until Bytes Hit?

      There was no indication from the OP that the file had any new lines in
      it.


      --
      - Nicholas Paldino [.NET/C# MVP]
      - mvp@spam.guard. caspershouse.co m

      "Kerem Gümrükcü" <kareem114@hotm ail.comwrote in message
      news:ORLoXErMIH A.2208@TK2MSFTN GP06.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."
      >

      Comment

      • Nicholas Paldino [.NET/C# MVP]

        #4
        Re: Read Stream Until Bytes Hit?

        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.

        --
        - Nicholas Paldino [.NET/C# MVP]
        - mvp@spam.guard. caspershouse.co m

        "coconet" <coconet@commun ity.nospamwrote in message
        news:lfutk3do90 2jhjlggnm0lclbs uoa55hg1i@4ax.c om...
        >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.
        >
        >

        Comment

        • Kerem Gümrükcü

          #5
          Re: Read Stream Until Bytes Hit?

          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."


          Comment

          • Nicholas Paldino [.NET/C# MVP]

            #6
            Re: Read Stream Until Bytes Hit?

            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.


            --
            - Nicholas Paldino [.NET/C# MVP]
            - mvp@spam.guard. caspershouse.co m

            "Kerem Gümrükcü" <kareem114@hotm ail.comwrote in message
            news:exj%23tRrM IHA.3940@TK2MSF TNGP05.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."
            >

            Comment

            • Peter Duniho

              #7
              Re: Read Stream Until Bytes Hit?

              On 2007-11-29 10:29:26 -0800, "Nicholas Paldino [.NET/C# MVP]"
              <mvp@spam.guard .caspershouse.c omsaid:
              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

              Comment

              • Jon Skeet [C# MVP]

                #8
                Re: Read Stream Until Bytes Hit?

                Nicholas Paldino [.NET/C# MVP] <mvp@spam.guard .caspershouse.c omwrote:
                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...

                --
                Jon Skeet - <skeet@pobox.co m>
                http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
                World class .NET training in the UK: http://iterativetraining.co.uk

                Comment

                • Kerem Gümrükcü

                  #9
                  Re: Read Stream Until Bytes Hit?

                  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;asdsds da;asdasdas;

                  or that way:

                  afwwerwe....;ae aw ;.a.....er...rg ter:;.- ; 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."


                  Comment

                  • Jeffrey Tan[MSFT]

                    #10
                    RE: Read Stream Until Bytes Hit?

                    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
                    Find official documentation, practical know-how, and expert guidance for builders working and troubleshooting in Microsoft products.

                    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/subscripti...t/default.aspx.
                    =============== =============== =============== =====
                    This posting is provided "AS IS" with no warranties, and confers no rights.

                    Comment

                    Working...