Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Create alphabetical grouping
Message
De
24/04/2016 09:58:28
James Blackburn
Qualty Design Systems, Inc.
Kuna, Idaho, États-Unis
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01635330
Message ID:
01635341
Vues:
59
Al gave you the correct answer but this index is simpler.
INDEX on CHRTRAN(MyUnit,"0123456789|.","") TAG myunit
>thanks for thought you put into this Al and the detailed explanations.
>I am trying to work with what you are suggesting and having negative results. where you write:
>INSERT INTO MyUnits ( MyUnit ) VALUES ( "T4.03||" )
>
>each unit is generated as a memory variable which I collect as a string - can I instead add this to my cursor as they happen instead of at the end:
>
>Here is the way it currently runs
>
>SCAN FOR field1 = 1
>A_unit=crs+LTRIM(STR(sct,5,2))+ '||'  &&& ie ('T4.01')
>mystr=mystr+A_unit
>endscan
>
>
>so can I plug in your cursor thus?
>
>
>SCAN FOR field1 = 1
>A_unit=crs+LTRIM(STR(sct,5,2))+ '||'  
>INSERT INTO MyUnits ( MyUnit ) VALUES ("&A_unit")
>endscan
>
>
>then at end of procedure add your concluding code ---- because unfortunately it ain't workin'
>
>LOCAL lcResult
>m.lcResult = ""
>SELECT MyUnits
>SCAN ALL
>	m.lcResult = m.lcResult + ALLTRIM( MyUnits.MyUnit )
>ENDSCAN
>?m.lcResult
>
>
>
>
>
>
>
>>>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
>>
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform