General information
Category:
Databases,Tables, Views, Indexing and SQL syntax
>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
Previous
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only