Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Inserting text using low level techniques
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00156635
Message ID:
00156649
Vues:
35
>>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
>Pete,
>If they are really lines (ended with cr/lf) try the following:
>
>rf = fopen('somefile.txt')
>wf = fcreate('otherfil.txt')
>for cntr = 1 to 2
>fputs(wf,fgets(rf))
>endfor
>fputs(wf,newline)
>do while not eof(rf)
>fputs(wf,fgets(rf))
>enddo
>fclose(rf)
>fclose(wf)
>
>When completed otherfil.txt will have what you want. By the way, rf and wf are my shorthand for read file and write file. If they are not really lines (not ended with cr/lf). Just do basically the same thing using fread() and fwrite() with the correct number of bytes specified. The key to this method working is that on every low level file read of write (of gets or puts) the byte pointer into the file is where you left it, that is, after the last read or write.
>Hope this works for you.
>-Dore

Thanks to you both,
I was trying to find a way of updating it keeping the original file name ( no need for rename etc... )
Regards
Pete Kane
Regards,
Peter J. Kane



Pete
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform