Posts: 858
Threads: 196
Joined: Apr 2005
How can I sort this:
ab1234/3:10
ab1234/3:9
bc3234/2:3
ch8218/5:2
ab1234/3:1
bc3234/2:2
---->
ab1234/3:1
ab1234/3:9
ab1234/3:10
bc3234/2:2
bc3234/2:3
ch8218/5:2
?
Posts: 12,035
Threads: 139
Joined: Dec 2002
Macro
out
str s=
;ab1234/3:10
;ab1234/3:9
;bc3234/2:3
;ch8218/5:2
;ab1234/3:1
;bc3234/2:2
ARRAY ( str ) a= s
a.sort( 0 sort_proc_str_logical 0 )
s= a
out s
Function
sort_proc_str_logical
function # param str & a str & b
dll - shlwapi # StrCmpLogicalW @* psz1 @* psz2
if ( _winver>= 0x501 ) ;;XP
, BSTR w1( a) w2( b)
, ret StrCmpLogicalW ( w1 w2)
else
, ret StrCompare ( a b 1 )
On Windows 2000 will sort differently, because StrCmpLogicalW is not available.
Posts: 858
Threads: 196
Joined: Apr 2005
Thanks, but the result is:
ab1234/3:1
ab1234/3:10
ab1234/3:9
bc3234/2:2
bc3234/2:3
ch8218/5:2
and it should be:
ab1234/3:1
ab1234/3:9
ab1234/3:10
bc3234/2:2
bc3234/2:3
ch8218/5:2
note 1: 9 before 10
note 2: This computer (W2000).
Posts: 12,035
Threads: 139
Joined: Dec 2002
StrCmpLogicalW - XP and later.
Posts: 858
Threads: 196
Joined: Apr 2005
Is possible to implement StrCmpLogicalW in QM?
Posts: 12,035
Threads: 139
Joined: Dec 2002
Maybe you can find source code on the internet.
Posts: 858
Threads: 196
Joined: Apr 2005
Posts: 12,035
Threads: 139
Joined: Dec 2002
cannot convert this. Look for C++ code.
Posts: 858
Threads: 196
Joined: Apr 2005
Does this help?
Attached Files
StrCmpLogicalW.zip (Size: 10.09 KB / Downloads: 327)
Posts: 12,035
Threads: 139
Joined: Dec 2002
you better look at the code. It uses StrCmpLogicalW and therefore will not work on w2000.
Posts: 12,035
Threads: 139
Joined: Dec 2002
This is not perfect and little tested.
Macro
out
str s=
;ab1234/3:10
;ab1234/3:9
;bc3234/2:3
;ch8218/5:2
;ab1234/3:1
;bc3234/2:2
ARRAY ( str ) a= s
;a.shuffle
a.sort( 0 sort_proc_str_logical 0 )
out a
Function
sort_proc_str_logical
function # param str & a str & b
ret StrCompareLogical ( a b)
;dll- shlwapi #StrCmpLogicalW @*psz1 @*psz2
;
;if(_winver>=0x501) ;;XP
, ;BSTR w1(a) w2(b)
, ;ret StrCmpLogicalW(w1 w2)
;else
, ;;ret StrCompare(a b 1)
, ;ret StrCompareLogical(a b)
Function
StrCompareLogical
;/
function # $ s1 $ s2
lpstr sn= "0123456789"
if ( findcs ( s1 sn) < 0 or findcs ( s2 sn) < 0 ) ret StrCompare ( s1 s2 1 )
str ss1( s1) ss2( s2)
REPLACERX r.frepl=& SCL_RxProc
ss1.replacerx( "\d+" r)
ss2.replacerx( "\d+" r)
;out ss1
ret StrCompare ( ss1 ss2 1 )
Function
SCL_RxProc
;/
function # REPLACERXCB & c
if ( c.match.len< 9 ) c.match.from( "000000000" + c.match.len c.match)
Posts: 858
Threads: 196
Joined: Apr 2005
Posts: 12,035
Threads: 139
Joined: Dec 2002
Also not perfect. And difficult to convert. Try my code, if something will not work as expected, I'll try to fix it.
Posts: 858
Threads: 196
Joined: Apr 2005
Thanks for all.
Otherwise.
Is there any easy way to extract the strings missing from the series?
In the example:
ab1234/3:2
ab1234/3:3
ab1234/3:4
ab1234/3:5
ab1234/3:6
ab1234/3:7
ab1234/3:8
bc3234/2:1
ch8218/5:1
Posts: 12,035
Threads: 139
Joined: Dec 2002
Posts: 858
Threads: 196
Joined: Apr 2005
Thanks again.
Macro
str a.getfile( "$desktop$\PRUEBA.TXT" )
str linea t1 t2 final
a.eliminar_lineas_vacias
foreach linea a
, if ( ! linea.end( "1" ))
,, int temp i numero
,, _s.get( linea find ( linea ":" ) + 1 )
,, ;out linea
,, ;out _s
,, numero= val ( _s)
,, for i numero 0 - 1
,,, t1.left( linea find ( linea ":" ))
,,, ;out t1
,,, t2.format( "%s:%i" t1 i)
,,, ;out t2
,,, if ( find ( a t2) < 0 )
,,,, final.formata( "%s[]" t2)
;out final
eliminar_lineas ( final "" "" 1 )
ARRAY ( str ) lii= final
lii.sort( 0 sort_proc_str_logical 0 )
final= lii
final.insertmultiline( " <---" - 1 )
str total.from( a final)
lii= total
lii.sort( 0 sort_proc_str_logical 0 )
total= lii
out total
total.setclip