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

Read text file to a certain point

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

tayspen
<Insert title here>
Team Colleague
1,622 posts since Jul 2005
Reputation Points: 84
Solved Threads: 99
 
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();
r0ckbaer
Junior Poster in Training
55 posts since Dec 2003
Reputation Points: 13
Solved Threads: 6
 

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


-T

tayspen
<Insert title here>
Team Colleague
1,622 posts since Jul 2005
Reputation Points: 84
Solved Threads: 99
 

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

tayspen
<Insert title here>
Team Colleague
1,622 posts since Jul 2005
Reputation Points: 84
Solved Threads: 99
 

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

ROGENATOR
Newbie Poster
17 posts since Sep 2005
Reputation Points: 11
Solved Threads: 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());
}

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

jaiprakashv
Newbie Poster
1 post since Aug 2008
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You