lines in a text file

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Apr 2009
Posts: 3
Reputation: nimbusania is an unknown quantity at this point 
Solved Threads: 0
nimbusania nimbusania is offline Offline
Newbie Poster

lines in a text file

 
0
  #1
Apr 26th, 2009
Hello,
I was just wondering how I would refer to a certain line in a text file. It is by using an index of some sort? here is my try:
  1. using (StreamReader worldlist = new StreamReader("wordlist.txt"))
  2. {
  3. string line;
  4. line = worldlist.ReadLine(count);
  5.  
  6. listBox1.Items.Add(line);
  7.  
  8. }

Unfortunately the error is "No overload for method 'ReadLine' takes '1'."
Please help?
N.
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 2,065
Reputation: Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice 
Solved Threads: 256
Featured Poster
Ramy Mahrous's Avatar
Ramy Mahrous Ramy Mahrous is offline Offline
Postaholic

Re: lines in a text file

 
0
  #2
Apr 26th, 2009
StreamReader.ReadLine() takes no arguments.
You can hold the text file string into string then cut\split it by '\n' then refer to the index of the array returned.
Here also an example: http://msdn.microsoft.com/en-us/libr....readline.aspx
Last edited by Ramy Mahrous; Apr 26th, 2009 at 9:12 am. Reason: Example added
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 3
Reputation: nimbusania is an unknown quantity at this point 
Solved Threads: 0
nimbusania nimbusania is offline Offline
Newbie Poster

Re: lines in a text file

 
0
  #3
Apr 26th, 2009
Originally Posted by Ramy Mahrous View Post
StreamReader.ReadLine() takes no arguments.
You can hold the text file string into string then cut\split it by '\n' then refer to the index of the array returned.
Here also an example: http://msdn.microsoft.com/en-us/libr....readline.aspx

Thanks, this is a great help.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 1
Reputation: ankurbhutani is an unknown quantity at this point 
Solved Threads: 0
ankurbhutani ankurbhutani is offline Offline
Newbie Poster

ankur bhutani

 
0
  #4
18 Days Ago
Originally Posted by nimbusania View Post
Hello,
I was just wondering how I would refer to a certain line in a text file. It is by using an index of some sort? here is my try:
  1. using (StreamReader worldlist = new StreamReader("wordlist.txt"))
  2. {
  3. string line;
  4. line = worldlist.ReadLine(count);
  5.  
  6. listBox1.Items.Add(line);
  7.  
  8. }

Unfortunately the error is "No overload for method 'ReadLine' takes '1'."
Please help?
N.

ans.the error occur caz ReadLine method cannt take any of the argument caz it hav to take value on the runtime
to take value on runtime ,in c#there is another procees of command line arguments
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,187
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 571
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast
 
0
  #5
18 Days Ago
  1. textBox1.Text = System.IO.File.ReadAllLines(@"C:\file.txt")[0]; //line 1
  2. textBox1.Text = System.IO.File.ReadAllLines(@"C:\file.txt")[1]; //line 2
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC