Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Inserting text using low level techniques
Message
De
11/11/1998 13:54:35
Donny Sims
Independent Computer Consultants Inc
Scottsboro, Alabama, États-Unis
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00156635
Message ID:
00156691
Vues:
28
>Hello All,
>does anyone know how to insert text at a specified point using Fopen, Fread etc?
>
>e.g.
>line1
>line2
>line3
>line4
>
>I want to insert newline line in between line2 and line3
>
>end result
>line1
>line2
>newline
>line3
>line4
>
>Thanks
>Pete Kane

Peter

This may be what you need is your file in not too large. I am assuming your lines end with a carrage return and line feed ( CHR(13)+CHR(10) ) so you might have to adjust for that.

FileHandle=FOPEN('YourFile') && Open the file
FileEnd=FSEEK(FileHandle, 0, 2) && Move pointer to EOF
=FSEEK(FileHandle, 0) && Move pointer back to BOF
FileStr = FREAD(FileHandle, FileEnd) && Store entire file to varable

* place everything after the 2nd crlf into EndStr
BreakAt = AT(CHR(13)+CHR(10),FileStr,2)+2
EndStr = SUBSTR(FileStr,BreakAt,FileEnd-BreakAt)

* insert your new line, you may need to add a crlf
FileStr = SUBSTR(FileStr,0,BreakAt)+newline+Endstr

* write it back to the file
=FWRITE(FileHandle,FileStr)

* close file
=FCLOSE(FileHandle)
Donny Sims

Life is what happens to us while were busy making other plans.
- John Lennon
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform