Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Single occurrence in a string
Message
De
29/03/2015 07:59:34
 
 
À
29/03/2015 07:49:32
Walter Meester
HoogkarspelPays-Bas
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows 7
Network:
Windows 2008 Server
Database:
Visual FoxPro
Application:
Desktop
Divers
Thread ID:
01617326
Message ID:
01617356
Vues:
63
>hmmm, Is it too late to enter the compiteition?
>
>
FUNCTION NonDupe(cString)
>LOCAL cNewStr 
> 
>cNewStr =""
>DO WHILE LEN(cString) > 0
>	cNewStr = cNewStr + LEFT(cString,1)
>	cString = STRTRAN(cString, LEFT(cString,1))
>ENDDO
>RETURN cNewStr
>ENDFUNC
>
>Which is shorter and faster than Marcia's alghorithm by 40% in my testing
>
>But all are nothing compared when you've got some C++ code working for you.
>The FoxTools.fll contains a function REDUCE() which is extremely fast on eliminating characters from a string.
>It has been written to reduce spaces but has a different role for other characters. It will remove them and replace with spaces.
>
>The following alghorith does not not work for detecting the space as a separate character, but if you're only concerned with non-space characters the following is about a 100 times faster than Marcia's routine.
>
>
>
FUNCTION NonDupe3(cString)
>LOCAL cNewStr 
> 
>cNewStr =""
>
>DO WHILE LEN(cString) > 0
>	cNewStr = cNewStr + LEFT(cString,1)
>	cString = LTRIM(REDUCE(cString, LEFT(cString,1)))
>ENDDO
>RETURN cNewStr
>ENDFUNC
>
>Walter,

Very nice algorithm Walter!
Fernando D. Bozzo
Madrid / Spain
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform