General information
Category:
Coding, syntax & commands
>>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
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only