Stream Reader Problem
-
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? :( Thanksoooo, the Jedi's will feel this one....
-
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? :( Thanksoooo, the Jedi's will feel this one....
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
-
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? :( Thanksoooo, the Jedi's will feel this one....
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
-
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
Just tried your suggestion. It still misses it out... :(
oooo, the Jedi's will feel this one....
-
Just tried your suggestion. It still misses it out... :(
oooo, the Jedi's will feel this one....
-
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
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....
-
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....
You mean it misses the first character of every line? File:
0Hello
1There
2Goodbyegives 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
-
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
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....
-
You mean it misses the first character of every line? File:
0Hello
1There
2Goodbyegives 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
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....
-
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....
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
-
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? :( Thanksoooo, the Jedi's will feel this one....
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.
-
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....
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
-
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
: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....
-
: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....
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