Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Reverse comma-delimited string
Message
De
04/09/2019 16:38:39
 
 
À
04/09/2019 16:04:02
Mike Yearwood
Toronto, Ontario, Canada
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01670542
Message ID:
01670581
Vues:
59
I had to tweak it a little to get it to match, but here are the results. In each of these element sets ALINES() m. was the fastest, so I just included those totals for comparison.
* 100 elements
0.410 ALINES() m.
0.327 OCCURS()

* 200 elements
1.091 ALINES() m.
1.416 OCCURS()

* 300 elements
2.013 ALINES() m.
2.686 OCCURS()

* 400 elements
3.491 ALINES() m.
4.570 OCCURS()

* 500 elements
5.089 ALINES() m.
6.642 OCCURS()
Here's the modified algorithm:
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=ALLTRIM(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+", "+LEFT(m.tcText,m.lnStart-2)
>>It doesn't pass the validation test. It returns an incorrect string. It's missing the first element in the list.
>Oops! Focused more on work than this little bit of fun.
>
>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
>lnEnd=m.lnStart-2
>lnStart=1
>lcRevString=m.lcRevString+","+SUBSTR(m.tcText,m.lnStart,m.lnEnd-m.lnStart+1)
>RETURN m.lcRevString
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform