1.11M Members

Read text file to a certain point

 
0
 

Ok so i want my program to read a text file to a certain point. Lets say to the line line that says fn: i then want it to read the one line only and only the the text after fn: and i want it to shoew that text in a text box. i no it can be done. but i dont know how. if any body knows would you min sharing

-T

 
0
 
StreamReader sr = new StreamReader("yourFileNameGoesHere", System.Text.Encoding.Default);
			string s = null;

			while ((s = sr.ReadLine()) != null)
			{
				if (s.IndexOf("fn:") != -1)
				{
					// ok, you found it
					// now you can do like 
					// textBox1.text = s;
					break;
				}
			}

			sr.Close();
 
0
 

Thank you so much, man you have helped me learn C# so much. I really thank you for all of your help.


-T

 
0
 

Thank you so much, man you have helped me learn C# so much. I really thank you for all of your help.


-T

hmmm but how can i make it so it only shos what comes after fn: not inl;uding fn:?

Question Answered as of 8 Years Ago by r0ckbaer
 
0
 

Grretings:
Just remove that part from the string:

s.Remove(0,3);

the remove method takes two parameter, the index where you want to start removing and length you wish to remove

 
0
 

Hi

Complete code to reading last line in text file

StreamReader streamReader = new StreamReader("HereWillBeYourTextFilePath");
    ArrayList lines = new ArrayList();

    string line;

    while ((line = streamReader.ReadLine()) != null)
    {
        lines.Add(line);
    }
    streamReader.Close();

    if (lines.Count > 0)
    {
        Response.Write(lines[lines.Count - 1].ToString());
    }

===============

Isn't it about time forums rewarded their contributors?

Earn rewards points for helping others. Gain kudos. Cash out. Get better answers yourself.

It's as simple as contributing editorial or replying to discussions labeled or OP Kudos

You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article