Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Editing txt file
Message
De
09/06/2009 05:57:42
 
 
À
09/06/2009 05:05:05
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows Server 2008
Divers
Thread ID:
01404651
Message ID:
01404653
Vues:
42
>Hi
>
>I have txt file with many lines ,each one is single lines, Sometimes The last line is empty.
>
>I want to add '^^^' (for example) in the end of each line.
>So the code job is:
>To scan each line and if the line not empty and the end of the line it's not ^^^, to add ^^^.
>
>Help Please
>
>Tnx
How about:

#DEFINE LF CHR(13)+CHR(10)


CLEAR
lcTail="^^^"

?" First crete a tst file"
TEXT TO lcText NOSHOW TEXTMERGE
line 1
line 2
line 3
line 4
NEXT line is empty

line 7
NEXT line is emptyagain

ENDTEXT

lcFileName="ThisIsPetersTestFile.txt"
IF NOT FILE(FULLPATH(lcfileName))
STRTOFILE(lcText, lcfileName)
ENDIF
?lcText
?"-------------------------------------------------------"

?"now work on it"
lcTextOut=[]
lcTextIn=FILETOSTR(FULLPATH(lcfileName))
lnNumLines= ALINES(laText,lcTextIn)
FOR I =1 TO lnNumLines

DO CASE
CASE empty(laText[m.I]) && empty line
lcTextOut = lcTextOut + laText[m.I] +LF
CASE lcTail$laText[m.I] && already has tail
lcTextOut = lcTextOut + laText[m.I]+LF

OTHERWISE
lcTextOut = lcTextOut + laText[m.I]+lcTail+LF

ENDCASE

ENDFOR

?lcTextOut
?"-------------------------------------------------------"
Peter Cortiel
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform