Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Create alphabetical grouping
Message
De
24/04/2016 00:42:47
Al Doman (En ligne)
M3 Enterprises Inc.
North Vancouver, Colombie Britannique, Canada
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01635330
Message ID:
01635332
Vues:
79
>Is there a way to present the following character string in alphabetical order:
>
>T4.03||T4.01||E2.05||W27||W211||
>re-ordered to
>E2.05||T4.01||T4.03||W27||W211||
>
>I am collecting the data one unit at a time (T4:03||) then (T4:01||)
>so perhaps while it is being collected it can be ordered.

You could create a cursor, index it appropriately and INSERT rows corresponding to each unit. Then SCAN the cursor and assemble the finished string.
CREATE CURSOR MyUnits ( MyUnit C( 7 ) )
INDEX ON LEFT( MyUnit, 1 ) + REPLICATE( "0", 7 -  LEN( ALLTRIM( MyUnit ) ) ) + SUBSTR( MyUnit, 2, LEN( ALLTRIM( MyUnit ) ) - 1 ) TAG MyUnit
* This INDEX expression is the trickiest bit, see notes below

* Gather values, INSERT into the cursor:
INSERT INTO MyUnits ( MyUnit ) VALUES ( "T4.03||" )
INSERT INTO MyUnits ( MyUnit ) VALUES ( "T4.01||" )
INSERT INTO MyUnits ( MyUnit ) VALUES ( "T2.05||" )
INSERT INTO MyUnits ( MyUnit ) VALUES ( "W27||" )
INSERT INTO MyUnits ( MyUnit ) VALUES ( "W211||" )

LOCAL lcResult
m.lcResult = ""

SELECT MyUnits
SCAN ALL
	m.lcResult = m.lcResult + ALLTRIM( MyUnits.MyUnit )

ENDSCAN

USE IN MyUnits

?m.lcResult

* Notes
* Figuring out how to sort/index is actually the trickiest part of your question
* Even that is relatively easy except for the W27||W211|| at the end
* If your strings always end (i.e. are delimited by) that pair at the end, it makes indexing easier
* You accumulate everything except those two strings in the cursor, then manually add those two strings at the end
* In that case you can simply
INDEX ON MyUnit TAG MyUnit

* If you want something that will work without knowing the finishing delimiter(s), what you can do is pad the total
* length of the final two strings in the index expression up to the 7 character length of the others. In your case
* in the index expression you would want them to be sorted as "W0027||" and "W0211||" in order to be sorted properly.
* The INDEX expression in the main code sample injects the proper number of zeroes
* in the proper location to pad the expression indexed to 7 characters
Regards. Al

"Violence is the last refuge of the incompetent." -- Isaac Asimov
"Never let your sense of morals prevent you from doing what is right." -- Isaac Asimov

Neither a despot, nor a doormat, be

Every app wants to be a database app when it grows up
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform