FUNCTION DeDupe(tcString) LOCAL lcNewString lcNewString = "" DO WHILE LEN(m.tcString)>0 && perhaps faster: ! m.tcString=="" lcNewString = m.lcNewString + Left(m.tcString, 1) tcString = CHRTRAN(m.tcString,Left(m.tcString, 1),"") ENDDO RETURN m.lcNewStringI expect my solution to be much faster than Tores if there are less than 5 different letters in a string of novel length (something like finding the acids in genome analysis), and as the number of different asc() values found in the string increases the time difference to decrease. But:
FUNCTION CommonSql Lparameters tcString Local lcReturn As String, ; lnX As Number Create Cursor curDummy (myChar Char(1), nPos I) For m.lnX = 1 To Len(m.tcString) Insert Into curDummy Values (Substr(m.tcString, m.lnX, 1), m.lnX) Endfor Select myChar, MIN(nPos) ; From curDummy ; Into Cursor curDummy ; GROUP BY 1 ; ORDER BY 2 m.lcReturn = [] Scan m.lcReturn = m.lcReturn + myChar endscan use in CurDummy Return m.lcReturnIn favor of the SQL/Cursor approach is the fact that the timings should be more robust/invariant to changes of count and distribution of count across the axis of elements found. In Marcias/my approach the time will be shorter if the chars occurring the highest number of times are found first compared to found last.