Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Converting wierd ASCII file to readable database format
Message
De
05/05/1999 05:49:41
Paul Frost
Instem Computer Systems Ltd
Stone, Royaume Uni
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00215249
Message ID:
00215253
Vues:
28
>Hello!
>
>I recieved a wierd ASCII file from a client of ours. He wants to have this ASCII file converted to a database format so I can make a VFP 6 application for him.
>
>The first line looks something like this:
>
>1 't Casteelken St.Pe s & Paulusstraat 2 8800 RUMBEKE 051/20.98.11 051/22.10.63
>
>All in one line (not several as in this message).
>
>The second line:
>2 't Meubelhof Rijksweg 477 3630 MAASMECHELE 089/76.19.23 089/77.18.16
>
>That it. But there isn't a real concistincy in it. It would be easy that all the fields would have a fixed length in every line. Not the case. On one line it's 20 and the other is 30 for instance.
>
>It's also quite a big file so editing it to proper format is to much work.
>
>Are there any good utilities to read wierd ASCII formats and convert them to a normal (.dbf for instance) format?
>
>Anyway to program something like this in VFP?
>
>Thanks for your feedback!

FGETS can be used to read ASCII files line by line.
Parse the line backwards from the end of the line looking for spaces, the first 5 spaces will give the last 5 fields, the remainder from the start of the line will be the first field.

I've sketched out the rough idea below - it's probably got a few bugs in, so check it out carefully.

fh = FOPEN( "xxx" )
DO WHILE NOT FEOF( fh )
raw = FGETS( fh )

endpos = LEN( raw )
FOR startpos = endpos TO 1 STEP -1
IF SUBSTR( raw, startpos, 1 ) = " "
EXIT
ENDIF
ENDFOR
field6 = SUBSTR( raw, startpos, endpos-startpos+1 )
endpos = startpos
* repeat above for loop for each field
*
ENDDO
FCLOSE( fh )

hth
Paul
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform