Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Stream Reader Problem

Stream Reader Problem

Scheduled Pinned Locked Moved C#
helpquestion
14 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Paul Unsworth
    wrote on last edited by
    #1

    Hi Guys I have quite an urgent problem which is really getting on my nerves... I have a stream reader which goes through a file line by line, and extracts information. The problem I have though, is that for some reason, the very first character is getting left out... string chkLine = ChkReader.ReadLine() Does anybody know why this could be happening? :( Thanks

    oooo, the Jedi's will feel this one....

    OriginalGriffO M L 3 Replies Last reply
    0
    • P Paul Unsworth

      Hi Guys I have quite an urgent problem which is really getting on my nerves... I have a stream reader which goes through a file line by line, and extracts information. The problem I have though, is that for some reason, the very first character is getting left out... string chkLine = ChkReader.ReadLine() Does anybody know why this could be happening? :( Thanks

      oooo, the Jedi's will feel this one....

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      Is the first character anything special? What encoding are you using? Is the first character even there - check with a hex editor? I use StreamReader quite a bit, and it's never given me a problem, and never left out any characters.

      No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      P 1 Reply Last reply
      0
      • P Paul Unsworth

        Hi Guys I have quite an urgent problem which is really getting on my nerves... I have a stream reader which goes through a file line by line, and extracts information. The problem I have though, is that for some reason, the very first character is getting left out... string chkLine = ChkReader.ReadLine() Does anybody know why this could be happening? :( Thanks

        oooo, the Jedi's will feel this one....

        M Offline
        M Offline
        MarkB777
        wrote on last edited by
        #3

        Try setting a break point in the below code snippet: foreach (char c in ChKReader.ReadLine()) {} See if it is picking it up using that.

        Mark Brock "We're definitely not going to make a G or a PG version of this. It's not PillowfightCraft." -- Chris Metzen

        P 1 Reply Last reply
        0
        • M MarkB777

          Try setting a break point in the below code snippet: foreach (char c in ChKReader.ReadLine()) {} See if it is picking it up using that.

          Mark Brock "We're definitely not going to make a G or a PG version of this. It's not PillowfightCraft." -- Chris Metzen

          P Offline
          P Offline
          Paul Unsworth
          wrote on last edited by
          #4

          Just tried your suggestion. It still misses it out... :(

          oooo, the Jedi's will feel this one....

          M 1 Reply Last reply
          0
          • P Paul Unsworth

            Just tried your suggestion. It still misses it out... :(

            oooo, the Jedi's will feel this one....

            M Offline
            M Offline
            MarkB777
            wrote on last edited by
            #5

            Is the text file ANSI encoded?

            Mark Brock "We're definitely not going to make a G or a PG version of this. It's not PillowfightCraft." -- Chris Metzen

            P 1 Reply Last reply
            0
            • OriginalGriffO OriginalGriff

              Is the first character anything special? What encoding are you using? Is the first character even there - check with a hex editor? I use StreamReader quite a bit, and it's never given me a problem, and never left out any characters.

              No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones

              P Offline
              P Offline
              Paul Unsworth
              wrote on last edited by
              #6

              The first character is a number. nothing special. It misses all of them though. It's not like it's just dropping a leading zero... It is very baffeling. Just does not make any sense. :(

              oooo, the Jedi's will feel this one....

              OriginalGriffO 1 Reply Last reply
              0
              • P Paul Unsworth

                The first character is a number. nothing special. It misses all of them though. It's not like it's just dropping a leading zero... It is very baffeling. Just does not make any sense. :(

                oooo, the Jedi's will feel this one....

                OriginalGriffO Offline
                OriginalGriffO Offline
                OriginalGriff
                wrote on last edited by
                #7

                You mean it misses the first character of every line? File:

                0Hello
                1There
                2Goodbye

                gives you three lines "hello", "There" and "Goodbye"? What is so different about your code from the standard and very boring:

                        using (StreamReader sr = new StreamReader(@"C:\\XXTemp\\Lines.txt"))
                            {
                            string s;
                            while ((s = sr.ReadLine()) != null)
                                {
                                MessageBox.Show(s);
                                }
                            }
                

                No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones

                "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                P 1 Reply Last reply
                0
                • M MarkB777

                  Is the text file ANSI encoded?

                  Mark Brock "We're definitely not going to make a G or a PG version of this. It's not PillowfightCraft." -- Chris Metzen

                  P Offline
                  P Offline
                  Paul Unsworth
                  wrote on last edited by
                  #8

                  Thats the assumption I'm making. Although I'm not sure how to check. The text file appears to be a straight forward text file for use with the likes of notepad.

                  oooo, the Jedi's will feel this one....

                  M 1 Reply Last reply
                  0
                  • OriginalGriffO OriginalGriff

                    You mean it misses the first character of every line? File:

                    0Hello
                    1There
                    2Goodbye

                    gives you three lines "hello", "There" and "Goodbye"? What is so different about your code from the standard and very boring:

                            using (StreamReader sr = new StreamReader(@"C:\\XXTemp\\Lines.txt"))
                                {
                                string s;
                                while ((s = sr.ReadLine()) != null)
                                    {
                                    MessageBox.Show(s);
                                    }
                                }
                    

                    No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones

                    P Offline
                    P Offline
                    Paul Unsworth
                    wrote on last edited by
                    #9

                    My code is:

                    while (chkReader.Read())
                    {
                    string chkLine = chkReader.ReadLine();
                    }

                    I just created a new text file of my very own and pointed my app at it and got the following: Actual line in file: "Hello There" Line picked up in chkReader.ReadLine(): "ello There" :sigh:

                    oooo, the Jedi's will feel this one....

                    OriginalGriffO 1 Reply Last reply
                    0
                    • P Paul Unsworth

                      Thats the assumption I'm making. Although I'm not sure how to check. The text file appears to be a straight forward text file for use with the likes of notepad.

                      oooo, the Jedi's will feel this one....

                      M Offline
                      M Offline
                      MarkB777
                      wrote on last edited by
                      #10

                      Well its hard to say, I would try creating a whole new text file, and typing in a few of the problem lines. That way you will know if the problem is the text file or your code. The code you posted should work fine...

                      Mark Brock "We're definitely not going to make a G or a PG version of this. It's not PillowfightCraft." -- Chris Metzen

                      1 Reply Last reply
                      0
                      • P Paul Unsworth

                        Hi Guys I have quite an urgent problem which is really getting on my nerves... I have a stream reader which goes through a file line by line, and extracts information. The problem I have though, is that for some reason, the very first character is getting left out... string chkLine = ChkReader.ReadLine() Does anybody know why this could be happening? :( Thanks

                        oooo, the Jedi's will feel this one....

                        L Offline
                        L Offline
                        Luc Pattyn
                        wrote on last edited by
                        #11

                        Hi, you could create your special stream reader that does exactly that, or there could be something very special about your file (not sure what). To make sure, use a hex editor/dumper to look at the first few lines of data. :)

                        Luc Pattyn [Forum Guidelines] [My Articles]


                        The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


                        1 Reply Last reply
                        0
                        • P Paul Unsworth

                          My code is:

                          while (chkReader.Read())
                          {
                          string chkLine = chkReader.ReadLine();
                          }

                          I just created a new text file of my very own and pointed my app at it and got the following: Actual line in file: "Hello There" Line picked up in chkReader.ReadLine(): "ello There" :sigh:

                          oooo, the Jedi's will feel this one....

                          OriginalGriffO Offline
                          OriginalGriffO Offline
                          OriginalGriff
                          wrote on last edited by
                          #12

                          There's your problem: the while(chkReader.Read()) reads and discards the first character of each line...

                          No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones

                          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                          P 1 Reply Last reply
                          0
                          • OriginalGriffO OriginalGriff

                            There's your problem: the while(chkReader.Read()) reads and discards the first character of each line...

                            No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones

                            P Offline
                            P Offline
                            Paul Unsworth
                            wrote on last edited by
                            #13

                            :doh: Your completely right... I can't believe I didn't spot that... More coffee is required me thinks!!! Thank you :-D

                            oooo, the Jedi's will feel this one....

                            OriginalGriffO 1 Reply Last reply
                            0
                            • P Paul Unsworth

                              :doh: Your completely right... I can't believe I didn't spot that... More coffee is required me thinks!!! Thank you :-D

                              oooo, the Jedi's will feel this one....

                              OriginalGriffO Offline
                              OriginalGriffO Offline
                              OriginalGriff
                              wrote on last edited by
                              #14

                              You're welcome - I have days like that meself!

                              No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones

                              "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                              "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                              1 Reply Last reply
                              0
                              Reply
                              • Reply as topic
                              Log in to reply
                              • Oldest to Newest
                              • Newest to Oldest
                              • Most Votes


                              • Login

                              • Don't have an account? Register

                              • Login or register to search.
                              • First post
                                Last post
                              0
                              • Categories
                              • Recent
                              • Tags
                              • Popular
                              • World
                              • Users
                              • Groups