May 7, 2007 #1 Squall8046 Programmer Joined May 7, 2007 Messages 1 Location US Im having problems reading the last line of a text file and I was wondering if anyone had any suggestions.
Im having problems reading the last line of a text file and I was wondering if anyone had any suggestions.
May 7, 2007 #2 cLFlaVA Programmer Joined Jun 14, 2004 Messages 6,450 Location US suggestion: show us the code you're using so we can tell you how to resolve your problem. *cLFlaVA ---------------------------- [tt]"quote goes here"[/tt] [URL unfurl="true"]http://www.coryarthus.com/[/url] Upvote 0 Downvote
suggestion: show us the code you're using so we can tell you how to resolve your problem. *cLFlaVA ---------------------------- [tt]"quote goes here"[/tt] [URL unfurl="true"]http://www.coryarthus.com/[/url]
May 7, 2007 #3 monksnake Programmer Joined Oct 14, 2005 Messages 2,145 Location US 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. <. Upvote 0 Downvote
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. <.
May 7, 2007 #4 cLFlaVA Programmer Joined Jun 14, 2004 Messages 6,450 Location US 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] Upvote 0 Downvote
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]
May 7, 2007 #5 monksnake Programmer Joined Oct 14, 2005 Messages 2,145 Location US otherwise your last line may be a blank string. Click to expand... Heh, well it still would be the last line. <. Upvote 0 Downvote
otherwise your last line may be a blank string. Click to expand... Heh, well it still would be the last line. <.