Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Read the text file contents from bottom to top
Message
From
29/11/2003 12:12:24
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivia
 
 
To
29/11/2003 12:06:47
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00854392
Message ID:
00854453
Views:
13
This is appropriate for relatively small files; it might be slow if the text file can grow very large. For this reason, I had suggested LLFF. However, reading the entire file and writing it back is easier, and it can be appropriate, depending on the expected file size.

>>I want to read the text file contents from bottom to top line by line and simultaneously delete the line from bottom top line by line.
>
>Ravi,
>
>Assume lines are sepatared by CRLF, or only by CR or LF.
>
>
>lcOldText = FileToStr('filename')
>lnCR = RAT(CHR(13),lcFileText)
>lnLF = RAT(CHR(10),lcFileText)
>IF lnLF - lnCR = 1
>  * There is a CRLF or only a LF in position 1
>  lcLastLine = SUBSTR(lcOldText,lnLF+1)
>  lcNewText = LEFT(lcOldText,lnCR-1)
>ELSE
>  * Lines are separated by a lone CR or LF
>  lcLastLine = SUBSTR(lcOldText,MAX(lnCR,lnLF)+1)
>  lcNewText = LEFT(lcOldText,MAX(lnCR,lnLF)-1))
>ENDIF
>StrToFile(lcNewText,'filename')
>
>
>Alex
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)
Previous
Reply
Map
View

Click here to load this message in the networking platform