Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to get lines from text file
Message
De
31/08/2006 09:41:55
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
31/08/2006 09:32:55
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 7 SP1
OS:
Windows '98
Database:
Visual FoxPro
Divers
Thread ID:
01149836
Message ID:
01150116
Vues:
39
>>>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

Greg,
You're right. I missed you're adding an extra CRLF at top.
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
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform