954,518 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

lines in a text file

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:

using (StreamReader worldlist = new StreamReader("wordlist.txt"))
                            {
                                string line;
                                line = worldlist.ReadLine(count);

                                listBox1.Items.Add(line);

                            }


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

nimbusania
Newbie Poster
3 posts since Apr 2009
Reputation Points: 10
Solved Threads: 0
 

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/library/system.io.streamreader.readline.aspx

Ramy Mahrous
Postaholic
2,196 posts since Aug 2006
Reputation Points: 480
Solved Threads: 276
 
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/library/system.io.streamreader.readline.aspx


Thanks, this is a great help.

nimbusania
Newbie Poster
3 posts since Apr 2009
Reputation Points: 10
Solved Threads: 0
 

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:

using (StreamReader worldlist = new StreamReader("wordlist.txt"))
                            {
                                string line;
                                line = worldlist.ReadLine(count);

                                listBox1.Items.Add(line);

                            }

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

ankurbhutani
Newbie Poster
1 post since Oct 2009
Reputation Points: 10
Solved Threads: 0
 
textBox1.Text = System.IO.File.ReadAllLines(@"C:\file.txt")[0]; //line 1
      textBox1.Text = System.IO.File.ReadAllLines(@"C:\file.txt")[1]; //line 2
sknake
Industrious Poster
4,954 posts since Feb 2009
Reputation Points: 1,764
Solved Threads: 735
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You