INDEX on CHRTRAN(MyUnit,"0123456789|.","") TAG myunit>thanks for thought you put into this Al and the detailed explanations.
>SCAN FOR field1 = 1 >A_unit=crs+LTRIM(STR(sct,5,2))+ '||' &&& ie ('T4.01') >mystr=mystr+A_unit >endscan >>
> >SCAN FOR field1 = 1 >A_unit=crs+LTRIM(STR(sct,5,2))+ '||' >INSERT INTO MyUnits ( MyUnit ) VALUES ("&A_unit") >endscan >>
>LOCAL lcResult >m.lcResult = "" >SELECT MyUnits >SCAN ALL > m.lcResult = m.lcResult + ALLTRIM( MyUnits.MyUnit ) >ENDSCAN >?m.lcResult > >>
>>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 >>