Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Converting wierd ASCII file to readable database format
Message
 
À
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:
00215270
Vues:
32
>
>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

RAT(' ',lcData) would be quicker than a for loop. Returns the position of the character in one call.
DO WHILE AT(' ',lcData)
    lcLineData=SUBSTR(lcData,RAT(' ',lcData)+1)
    lcData=LEFT(lcData,RAT(' ',lcData)-1)
*   extract line data here
ENDDO
*lcData contains first line here
I don't think this will work in this case because you can't be certain that the data on one line doesn't include a space.

I certainly can't think of any solution. I've done this sort of thing many, many times but usually find some kind of pattern or separator.

Michiel: try using a hex editor on the text file - you may find a non-space character where you thought the space was. Make sure you use the original file (reload it if necessary) as some utilities put spaces where you don't want them. I believe there is a hexedit program with VFP5 (in tools, I think).
Nigel B Coates
NBC Software Services
Dublin, Ireland.
eMail: Nigel.Coates@NBCSoftware.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform