Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Single occurrence in a string
Message
 
À
27/03/2015 13:25:38
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:
01617455
Vues:
95
>Hi All:
>
>How do I remove duplicate characters in a string:
>
>
>Bigstring = 'cattttccv'
>NonDupeString = NonDupe(BigString)
>
>* Result = 'catv'
>
>
>Thanks,
>
>Yossi

I must say that I am not comfortable posting my solution with all the backslash going around from useless people that only come here to confront or incite worthless fights... Maybe Fernando can time it to see if it worth pursuing it but I think it is very fast:
lcText				= REPLICATE('ccaaaaattttttttttvvvv', 102400)
lnStart				= SECONDS()
loRegExp			= Createobject('VBScript.RegExp')

with loRegexp as VBScript.RegExp
	.IgnoreCase			= .t.
	.Global				= .t.
	.Multiline			= .T.
	.Pattern			= '(\w)(\1+)'
	lcNewText			= .Replace(lcText, '$1')
endwith

? SECONDS() - lnStart, LEN(lcNewText)
(and by the way, this solution is very generic, it can be implemented in any language)
"The five senses obstruct or deform the apprehension of reality."
Jorge L. Borges?

"Premature optimization is the root of all evil in programming."
Donald Knuth, repeating C. A. R. Hoare

"To die for a religion is easier than to live it absolutely"
Jorge L. Borges
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform