Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to get lines from text file
Message
From
31/08/2006 08:01:07
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
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:
01150095
Views:
25
>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.

Greg,
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).

PS: I don't understand why he needs an alternative to arrays (or fgets() - if max line length is not over 8192). Fgets() is the ultimate line reading IMHO.
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform