Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Why one code works, while other doesn't?
Message
 
 
À
22/01/2001 17:13:54
Dragan Nedeljkovich (En ligne)
Now officially retired
Zrenjanin, Serbia
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00466654
Message ID:
00467727
Vues:
31
>>I found a problem. Somehow the lcPattern variable definition was changed. Instead of
>>
lcPattern=left(tcDBFName,lnPos+1)+'???'+substr(tcDBFName,lnPos+4)
>>it was something different. Therefore the program just didn't do anything...
>>
>>I'm testing the speed difference right now.
>>
>>>>Should I revert the code back to the original cursor idea?
>>>
>>>As far as effeicent goes, I'd bet that the cursor idea is faster anyways, so yes. You could easily test it out.
>
>If speed is the issue, and you're replacing a character by character (not string by string), you may check using ChrTran() instead of StrTran() - it should be faster.
>
>Another handy trick, assuming you're replacing two characters with three question marks, instead of
>
lcPattern=left(tcDBFName,lnPos+1)+'???'+substr(tcDBFName,lnPos+4)
>you could use
>
lcPattern=Stuff(tcDBFName,lnPos+2, 2, '???')
>A single function should be faster than two functions plus two string concatenateions. Besides, I always thought that all the string chopping functions (left, right, substr()) are internally done as Stuff() with special parameters.

Yes, you're right.

This is the test:
local lcPatern, lnSec, lnPos, tcDBFName, i

tcDBFName=replicate("bkl",30)
lnPos=20
lnSec=seconds()
for i=1 to 100000
    lcPattern=left(tcDBFName,lnPos+1)+'???'+substr(tcDBFName,lnPos+4)
endfor
?seconds()-lnSec
lnSec=seconds()
for i=1 to 100000
   lcPattern=Stuff(tcDBFName,lnPos+2, 2, '???')
   endfor
?seconds()-lnSec
BTW, I can not use chrtran for chrtran(lcString,["],"") because of the bug in chrtran. David Frankenbah mentioned it, see the problem in WiKi.

Best wishes,
Nadya

P.S. You're older, than I thought :)
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform