Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to get lines from text file
Message
 
 
To
30/08/2006 22:41:59
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:
01150055
Views:
28
Greg,

Since you copied me on the reply... I wouldn't run that sort of code on a very large file at all. That's an O( n2 ) way of doing it. You are forcing strextract() to keep reprocessing the first part of the string for every line, that's horribly inefficient.

>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.
df (was a 10 time MVP)

df FoxPro website
FoxPro Wiki site online, editable knowledgebase
Previous
Reply
Map
View

Click here to load this message in the networking platform