Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Multiple conditional sorting
#1
Hello, everyone

The following code is sorted in descending A-Z order

How to set the second condition?
Use the first number of the comment to do the second sort condition!

Any suggestions are welcome. Thanks in advance

For example: the result of the current code sorting is as follows

Code:
Copy      Help
ax :sub.Sub2 ;;4test
ax :sub.Sub3 ;;2test
ax :sub.Sub4 ;;3test
ax :sub.Sub5 ;;1test
cbc :sub.Sub6 ;;2test
cbc :sub.Sub7 ;;1test
zbc :sub.Sub1 ;;test1

I expect the results:
Code:
Copy      Help
ax :sub.Sub5 ;;1test
ax :sub.Sub3 ;;2test
ax :sub.Sub4 ;;3test
ax :sub.Sub2 ;;4test
cbc :sub.Sub7 ;;1test
cbc :sub.Sub6 ;;2test
zbc :sub.Sub1 ;;test1

Macro Macro3
Code:
Copy      Help
str s=
;cbc :sub.Sub7 ;;1test
;cbc :sub.Sub6 ;;2test
;ax :sub.Sub5 ;;1test
;ax :sub.Sub4 ;;3test
;ax :sub.Sub3 ;;2test
;ax :sub.Sub2 ;;4test
;zbc :sub.Sub1 ;;test1

ARRAY(str) a=s
a.sort(2)
s=a
mes s
#2
need to use a callback function to accomplish this
Code:
Copy      Help
out
str s=
;cbc :sub.Sub7 ;;1test
;cbc :sub.Sub6 ;;2test
;ax :sub.Sub5 ;;1test
;ax :sub.Sub4 ;;3test
;ax :sub.Sub3 ;;2test
;ax :sub.Sub2 ;;4test
;zbc :sub.Sub1 ;;test1

ARRAY(str) a=s
a.sort(2 sub.Callback_q_sort)
s=a
out s.rtrim

#sub Callback_q_sort
function# param str&a str&b

str s.gett(a -1 ":") ;str ss.gett(b -1 ":")
if(StrCompare(s ss)=0)
,ret StrCompare(a+findcr(a ';')+1 b+findcr(b ';')+1 1)
else
,ret StrCompare(a b 1)


Forum Jump:


Users browsing this thread: 1 Guest(s)