Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Slow string processing.
Message
From
14/06/1999 19:19:59
 
 
To
14/06/1999 18:00:36
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00229755
Message ID:
00229777
Views:
20
Matt,

I do a bunch of string processing along these lines to read in text files of invoice payments. One of the first things I see that you could do that might speed up processing, is to find the position of the delimeter with "AT", the use "SUBSTR" to pull out the keyvalue.

For example, I have a text line with a set number of delimiters. First I have a for loop that stores off to variables the location in the line of the 10 delimiters. Then I have a command like(in pseudo code):

SUBSTR(textline, location of delimter + 1, location of end delimiter - location of start delimiter -1)

to get the value from the text string.

Once I have all the values, I process the variables as necessary.

PF


>Sure, here's the main loop below. The first DO WHILE and DO CASE are to find the key name, then the next DO WHILE and DO CASE are to extract the associated data piece. The end result is we want to find the field name in the table that is the same as key name and store the data piece in that field.
>
>All the nonsense with ~ and / is because they are the delimiters.
>
>I hope thats enough.
>
>Thanks.
>
>Matt
>
>
>**** CODE PIECE FOLLOWS
>
>do while mpos < len(mresult)
>
> keyname=""
> currchar=substr(mresult,mpos,1)
> if currchar="|"
> mpos=mpos+1
> currchar=substr(mresult,mpos,1)
> endif
> lastchar=substr(mresult,mpos-1,1)
> do while (currchar!="~" or (currchar="~" and lastchar="/")) and ;
> (currchar!="|" or (currchar="|" and lastchar="/")) and mpos < len(mresult)
> do case
> case inlist(currchar,"~","|","+") and lastchar="/"
> * Remove the last slash, its just an escape character
> keyname=left(keyname,len(keyname)-1)+currchar
> case inlist(currchar,"~","|","+") and (lastchar!="/" or empty(lastchar))
> * Not an escaped character, so don't add it
> otherwise
> keyname=keyname+currchar
> endcase
> mpos=mpos+1
> lastchar=currchar
> currchar=substr(mresult,mpos,1)
> enddo
>
> keydata=""
> currchar=substr(mresult,mpos,1)
> lastchar=substr(mresult,mpos-1,1)
> do while (currchar!="|" or (currchar="|" and lastchar="/")) and mpos < len(mresult)
> do case
> case inlist(currchar,"~","|","+") and lastchar="/"
> * Remove the last slash, its just an escape character
> keydata=left(keydata,len(keydata)-1)+currchar
> case inlist(currchar,"~","|","+") and (lastchar!="/" or empty(lastchar))
> * Not an escaped character, so don't add it
> otherwise
> keydata=keydata+currchar
> endcase
> mpos=mpos+1
> lastchar=currchar
> currchar=substr(mresult,mpos,1)
> enddo
>
>
> * Get the number off the end of the keyname to tell us what record we're working with
>
> mdigits=""
> numdigits=1
> do while val(right(keyname,numdigits))!=0 or right(keyname,numdigits)==replicate("0",numdigits)
> numdigits=numdigits+1
> enddo
> mdigits=right(keyname,numdigits-1)
> if !empty(mdigits)
> if val(mdigits)>workrec
> * New record needed
> workrec=val(mdigits)
> append blank
> endif
> endif
>
> * Gotta replace the digits with a _ in order to replace the field name
> if numdigits>1
> fieldname=left(keyname,len(keyname)-numdigits+1)+"_"
> else
> fieldname=keyname
> endif
>
> * Now fill the field
> set exact on
> if ascan(fnames,fieldname)>0 and !empty(fieldname)
> replace (fieldname) with keydata
> endif
>
>enddo

(On an infant's shirt): Already smarter than Bush
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform