944,057 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Marked Solved
  • Views: 12846
  • C# RSS
Sep 25th, 2005
0

Read text file to a certain point

Expand Post »
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
Similar Threads
Team Colleague
Reputation Points: 84
Solved Threads: 99
<Insert title here>
tayspen is offline Offline
1,542 posts
since Jul 2005
Sep 26th, 2005
0

Re: Read text file to a certain point

C# Syntax (Toggle Plain Text)
  1. StreamReader sr = new StreamReader("yourFileNameGoesHere", System.Text.Encoding.Default);
  2. string s = null;
  3.  
  4. while ((s = sr.ReadLine()) != null)
  5. {
  6. if (s.IndexOf("fn:") != -1)
  7. {
  8. // ok, you found it
  9. // now you can do like
  10. // textBox1.text = s;
  11. break;
  12. }
  13. }
  14.  
  15. sr.Close();
Reputation Points: 13
Solved Threads: 6
Junior Poster in Training
r0ckbaer is offline Offline
55 posts
since Dec 2003
Sep 26th, 2005
0

Re: Read text file to a certain point

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


-T
Team Colleague
Reputation Points: 84
Solved Threads: 99
<Insert title here>
tayspen is offline Offline
1,542 posts
since Jul 2005
Sep 26th, 2005
0

Re: Read text file to a certain point

Quote originally posted by tayspen ...
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:?
Team Colleague
Reputation Points: 84
Solved Threads: 99
<Insert title here>
tayspen is offline Offline
1,542 posts
since Jul 2005
Sep 29th, 2005
0

Re: Read text file to a certain point

Grretings:
Just remove that part from the string:
C# Syntax (Toggle Plain Text)
  1. s.Remove(0,3);
the remove method takes two parameter, the index where you want to start removing and length you wish to remove
Reputation Points: 11
Solved Threads: 0
Newbie Poster
ROGENATOR is offline Offline
17 posts
since Sep 2005
May 22nd, 2009
0

Re: Read text file to a certain point

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

===============
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jaiprakashv is offline Offline
1 posts
since Aug 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Setup and deployment project problem
Next Thread in C# Forum Timeline: How Insert Data Using EntityDataSource in FormView





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC