Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading the last line of a text file

Status
Not open for further replies.

Squall8046

Programmer
May 7, 2007
1
US
Im having problems reading the last line of a text file and I was wondering if anyone had any suggestions.
 
You can use the .ReadAll() method to put the entire text into a string, then use the split method to put that text into an array.

You would split on the \n or \r characters. I'd do a global replace on the \r (hard return) changing it into a \n (newline) then split on the \n.

Then all you have to do is grab the last element of the array that was created with the split method.

[monkey][snake] <.
 
monksnake,

technically you'd want to do a trim before splitting, using a regex. otherwise your last line may be a blank string.

just throwing it out there as another point to take away.



*cLFlaVA
----------------------------
[tt]"quote goes here"[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top