Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Single occurrence in a string
Message
De
30/03/2015 10:46:25
Walter Meester
HoogkarspelPays-Bas
 
 
À
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:
01617401
Vues:
83
J'aime (1)
>Hi All:
>
>How do I remove duplicate characters in a string:
>
>
>Bigstring = 'cattttccv'
>NonDupeString = NonDupe(BigString)
>
>* Result = 'catv'
>
>
>Thanks,
>
>Yossi

Hi jossy

Another approach,
FUNCTION NonDupe4(cString)
LOCAL cNewStr, nT, aX[255,2]

cNewStr = ""
FOR nT = 1 TO 255
	aX[nT,1] = AT(CHR(nT), cString)
	aX[nT,2] = CHR(nT)
ENDFOR

=ASORT(aX,1) && order on the found position, to preserve the order

FOR nT = 1 TO 255
		cNewStr = cNewStr + IIF(aX[nT,1] > 0, ax[nT,2], "")
ENDFOR
RETURN cNewStr
For John... yes, as you can see I "refactored" Marcia's solution because I'm using the same names.
It is as 5 times as slow as the REDUCE() solution, but other than that far faster than the others.

Walter,
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform