Read text file to a certain point

Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jul 2005
Posts: 1,542
Reputation: tayspen is on a distinguished road 
Solved Threads: 98
Team Colleague
tayspen's Avatar
tayspen tayspen is offline Offline
<Insert title here>

Read text file to a certain point

 
0
  #1
Sep 25th, 2005
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
Firefox
Ewido
Tune up windows
Get detailed system information
My Fixes

Member - Alliance of Security Analysis Professionals - Since 2006
Reply With Quote Quick reply to this message  
Join Date: Dec 2003
Posts: 55
Reputation: r0ckbaer is an unknown quantity at this point 
Solved Threads: 6
r0ckbaer r0ckbaer is offline Offline
Junior Poster in Training

Re: Read text file to a certain point

 
0
  #2
Sep 26th, 2005
  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();
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1,542
Reputation: tayspen is on a distinguished road 
Solved Threads: 98
Team Colleague
tayspen's Avatar
tayspen tayspen is offline Offline
<Insert title here>

Re: Read text file to a certain point

 
0
  #3
Sep 26th, 2005
Thank you so much, man you have helped me learn C# so much. I really thank you for all of your help.


-T
Firefox
Ewido
Tune up windows
Get detailed system information
My Fixes

Member - Alliance of Security Analysis Professionals - Since 2006
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1,542
Reputation: tayspen is on a distinguished road 
Solved Threads: 98
Team Colleague
tayspen's Avatar
tayspen tayspen is offline Offline
<Insert title here>

Re: Read text file to a certain point

 
0
  #4
Sep 26th, 2005
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:?
Firefox
Ewido
Tune up windows
Get detailed system information
My Fixes

Member - Alliance of Security Analysis Professionals - Since 2006
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 17
Reputation: ROGENATOR is an unknown quantity at this point 
Solved Threads: 0
ROGENATOR's Avatar
ROGENATOR ROGENATOR is offline Offline
Newbie Poster

Re: Read text file to a certain point

 
0
  #5
Sep 29th, 2005
Grretings:
Just remove that part from the string:
  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
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1
Reputation: jaiprakashv is an unknown quantity at this point 
Solved Threads: 0
jaiprakashv jaiprakashv is offline Offline
Newbie Poster

Re: Read text file to a certain point

 
0
  #6
May 22nd, 2009
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());
}

===============
Happy Coding

Thanks

http://www.interviewsworld.com
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC