Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to get lines from text file
Message
From
31/08/2006 09:32:55
 
 
To
31/08/2006 08:01:07
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 7 SP1
OS:
Windows '98
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01149836
Message ID:
01150114
Views:
30
>>An alternative to arrays:
>>
>>
>>#DEFINE CRLF CHR(13)+CHR(10)
>>LOCAL lcText, lnNumLines, lnLine, lcLine
>>lcText = CRLF + FILETOSTR("myfile.txt")
>>IF RIGHT(lcText,2) = CRLF
>> lnNumLines = OCCURS(CRLF,lcText) - 1
>>ELSE
>> lnNumLines = OCCURS(CRLF,lcText)
>>ENDIF
>>FOR lnLine=1 TO lnNumLines
>> lcLine = STREXTRACT(lcText,CRLF,CRLF,lnLine,2)
>> ? lcLine
>>ENDFOR
>>
>>
>>The CRLF is added to the beginning to allow STREXTRACT to extract the first line.
>
>As per CC, here is my idea:
>1) It'd fail if file has a single line with no CRLF in it (or last line has no CRLF and missed).
>2) StrExtract() would be slow (needs to locate the occurence on each call).

To your response, for 1 -- no it does not fail -- the last parameter ('2') does not require the last line to have a delimiter present. For 2 -- yes it is slow and I necessarily would not use it, but the person requested a non-array method. My preference would have used ALINES() function and then process in a FOR loop.

Greg
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform