Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Single occurrence in a string
Message
From
30/03/2015 10:46:25
Walter Meester
HoogkarspelNetherlands
 
 
To
27/03/2015 13:25:38
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows 7
Network:
Windows 2008 Server
Database:
Visual FoxPro
Application:
Desktop
Miscellaneous
Thread ID:
01617326
Message ID:
01617401
Views:
84
Likes (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,
Previous
Reply
Map
View

Click here to load this message in the networking platform