Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Delimited with colon
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00038100
Message ID:
00038120
Vues:
41
>I am trying to append a text file where fields are seperated by colon, So I try the command
>
>Append From textfiles type delimited with :
>
>However, it doesn't seem to evaluate the colon instead it take as a string and appended whole record as one field.
>
>Thanx in advance!!

Sam:

I just tried appending a test textfile with data delimited with a colon. Two common ways of doing this yielded different but unsatisfactory results.

option 1:

set delimiter to ":"
append from testfile delimited

option 2:

append from testfile delimited with :


So, this leaves a more complicated solution. Low level reading of the file and manually picking out the data between the colons (FOPEN(), FREAD(), FSEEK(), etc.)

use sometable
gnFileHandle = FOPEN('textfile.txt') && opens the text file
=FSEEK(gnFileHandle, 0) && move pointer to top of file
do while !feof()
lcString = FREAD(gnFilehandle, 254) && reads 1 full line
*
* start "substringing" your fields from lcString here
*
lcField1 = substr(lcString, 1, at(":",lcString,1)-1)
lcField2 = substr(lcString, at(":",lcString,1)+1, at(":",lcString,2)-1)
.
.
append blank
replace sometable.field1 with lcField1,...
enddo
= FCLOSE(gnFileHandle) && Close the file

There are adequate examples in the VFP help under the FREAD(), FOPEN(), etc., subjects.

HTH
Mark McCasland
Midlothian, TX USA
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform