Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Reverse comma-delimited string
Message
De
04/09/2019 14:49:41
Mike Yearwood
Toronto, Ontario, Canada
 
 
À
04/09/2019 14:25:47
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01670542
Message ID:
01670575
Vues:
67
Hey Rick

Add this one
FUNCTION reverse_occurs_AT_mdot_unconditional
LPARAMETERS m.tcText
IF NOT ","$m.tcText
	RETURN m.tcText
ENDIF
LOCAL lnLines,lcRevString,lnStart,lnEnd
lnLines=OCCURS(",",m.tcText)+1
lnEnd=LEN(m.tcText)
lnStart=AT(",",m.tcText,m.lnLines-1)+1
lcRevString=SUBSTR(m.tcText,m.lnStart,m.lnEnd-m.lnStart+1)
FOR x = m.lnLines-2 TO 1 STEP -1
	lnEnd=m.lnStart-2
	lnStart=AT(",",m.tcText,m.x)+1
	lcRevString=m.lcRevString+","+SUBSTR(m.tcText,m.lnStart,m.lnEnd-m.lnStart+1)
ENDFOR x
RETURN m.lcRevString
>>>Here's one that shows iteration for various length strings in 100-element increments, and in 10-element increments up to 50. ALINES() becomes considerably faster the larger the element list. The crossover seems to happen around 40 elements.
>>Right, that matches my experience. ALINES() is linear. GETWORDxxx() is not.
>
>Here's another version which uses MEMLINES() with these changes.
>
>
* 100 elements
>* 0.451 ALINES()
>* 1.093 MEMLINES()
>
>* 200 elements
>* 1.128 ALINES()
>* 4.097 MEMLINES()
>
>* 300 elements
>* 2.301 ALINES()
>* 8.763 MEMLINES()
>
>* 400 elements
>* 3.670 ALINES()
>* 15.230 MEMLINES()
>
>* 500 elements
>* 5.744 ALINES()
>* 24.424 MEMLINES()
>
>
>* Code
>    CREATE CURSOR c_memlines (cText m)
>    INSERT INTO c_memlines (cText) VALUES (CHRTRAN(lcForward, ",", CHR(13)))
>
>FUNCTION reverse_memlines
>LOCAL lnLines, lcText, lnI
>LOCAL ARRAY laLines[1]
>    IF CHR(13) $ c_memlines.cText
>        lnLines = MEMLINES(c_memlines.cText)
>        lcText  = ALLTRIM(MLINE(c_memlines.cText, lnLines))
>        FOR lnI = lnLines - 1 TO 1 STEP -1
>            lcText = lcText + ", " + ALLTRIM(MLINE(c_memlines.cText, lnI))
>        NEXT
>        RETURN lcText
>    ENDIF
>    RETURN c_memlines.cText
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform