File input method returning blank lines

Thread Solved

Join Date: Jul 2009
Posts: 31
Reputation: tdeck is an unknown quantity at this point 
Solved Threads: 0
tdeck tdeck is offline Offline
Light Poster

File input method returning blank lines

 
0
  #1
Jul 17th, 2009
As far as I can tell, this method is returning a blank line every other line, but I can't figure out why:
  1. public static List<string> plain(string path, int num)
  2. {
  3. List<string> result = new List<string>();
  4. StreamReader reader = File.OpenText(path);
  5. string line;
  6. int i = 0;
  7. while ((line = reader.ReadLine()) != null)
  8. {
  9. result.Add(line);
  10. i++;
  11. if (i == num) { break; }
  12. }
  13. return result;
  14. }

Does anyone have an idea? I'm sure it's something simple I'm overlooking .
Last edited by tdeck; Jul 17th, 2009 at 2:07 pm.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 64
Reputation: lighthead is on a distinguished road 
Solved Threads: 15
lighthead's Avatar
lighthead lighthead is offline Offline
Junior Poster in Training

Re: File input method returning blank lines

 
1
  #2
Jul 17th, 2009
Your function is correctly returning a list of at most 'num' lines in the file. There were no blank lines. You might want to recheck other parts of the program.
Everybody Lies.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 254
Reputation: Antenka has a spectacular aura about Antenka has a spectacular aura about Antenka has a spectacular aura about 
Solved Threads: 65
Antenka's Avatar
Antenka Antenka is offline Offline
Posting Whiz in Training

Re: File input method returning blank lines

 
1
  #3
Jul 17th, 2009
Yeah .. it also works fine here.

P.S. Are you sure, that your file, which lays in path has text in it (maybe this is that simple, that you're overlooking )?
So what if you can see the darkest side of me?
No one would ever change this animal I have become
Help me believe it's not the real me
Somebody help me tame this animal
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 31
Reputation: tdeck is an unknown quantity at this point 
Solved Threads: 0
tdeck tdeck is offline Offline
Light Poster

Re: File input method returning blank lines

 
0
  #4
Jul 17th, 2009
Hmm... I think it's the input file I used. It's generated from a python script, and I think the script replaced the \n with \r\n. So, since I'm sending \r\n, it puts \r\r\n in the file. Which, oddly, shows up as just one line break in notepad and textpad .

In case you're curious:
http://www.python-forum.org/pythonfo...=13807&start=0

-Weird
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 147
Reputation: sid78669 is an unknown quantity at this point 
Solved Threads: 7
sid78669's Avatar
sid78669 sid78669 is offline Offline
Junior Poster

Re: File input method returning blank lines

 
0
  #5
Jul 17th, 2009
In that case you might want to use this:
  1. line.Replace("\\r\\r\\n", "");

That should fix it :-)
Live free.... Die Hard!
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 31
Reputation: tdeck is an unknown quantity at this point 
Solved Threads: 0
tdeck tdeck is offline Offline
Light Poster

Re: File input method returning blank lines

 
0
  #6
Jul 17th, 2009
Yeah I just wrote a Python script to fix the files. Python's pretty quick to write, this is the first time it has frustrated me .
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 64
Reputation: lighthead is on a distinguished road 
Solved Threads: 15
lighthead's Avatar
lighthead lighthead is offline Offline
Junior Poster in Training

Re: File input method returning blank lines

 
0
  #7
Jul 17th, 2009
Mark it as solved.
Everybody Lies.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 498 | Replies: 6
Thread Tools Search this Thread



Tag cloud for C#
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC