1,105,592 Community Members

Read text file to a certain point

Member Avatar
tayspen
<Insert title here>
1,582 posts since Jul 2005
Reputation Points: 28 [?]
Q&As Helped to Solve: 104 [?]
Skill Endorsements: 0 [?]
Team Colleague
 
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

Member Avatar
r0ckbaer
Junior Poster in Training
55 posts since Dec 2003
Reputation Points: 3 [?]
Q&As Helped to Solve: 6 [?]
Skill Endorsements: 0 [?]
 
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();
Member Avatar
tayspen
<Insert title here>
1,582 posts since Jul 2005
Reputation Points: 28 [?]
Q&As Helped to Solve: 104 [?]
Skill Endorsements: 0 [?]
Team Colleague
 
0
 

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


-T

Member Avatar
tayspen
<Insert title here>
1,582 posts since Jul 2005
Reputation Points: 28 [?]
Q&As Helped to Solve: 104 [?]
Skill Endorsements: 0 [?]
Team Colleague
 
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
Member Avatar
ROGENATOR
Newbie Poster
17 posts since Sep 2005
Reputation Points: 1 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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

Member Avatar
jaiprakashv
Newbie Poster
1 post since Aug 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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());
    }

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

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