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

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

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


-T

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:?

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

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.