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

4
Contributors
5
Replies
6
Views
12 Years
Discussion Span
Last Post by jaiprakashv
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:?

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());
    }

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

Edited by Reverend Jim: Fixed formatting

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.