Sort
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- VIP Livecode Opensource Backer
- Posts: 2262
- Joined: Thu Feb 28, 2013 11:52 pm
- Location: Göttingen, DE
Re: Sort
Is the itemdelimiter tab and you wish to sort lexicographically (co-sorted) numeric by the 8 comma-items of tab-item 3?
Field 1:
(USE "#" instead of tab here only to make it better visible)
19-2#Z#04,05,06,08,09,21,27,31#202
10-1#Z#02,03,08,11,18,24,25,31#207
14-1#Z#01,05,08,11,20,22,25,32#252
13-1#Z#04,06,07,09,18,22,28,32#172
Field 1 is now lexicographically ordered (numeric) by the 8 comma-items of tab-item 3
(USE "#" instead of tab here only to make it better visible)
14-1#Z#01,05,08,11,20,22,25,32#252
10-1#Z#02,03,08,11,18,24,25,31#207
19-2#Z#04,05,06,08,09,21,27,31#202
13-1#Z#04,06,07,09,18,22,28,32#172
Field 1:
(USE "#" instead of tab here only to make it better visible)
19-2#Z#04,05,06,08,09,21,27,31#202
10-1#Z#02,03,08,11,18,24,25,31#207
14-1#Z#01,05,08,11,20,22,25,32#252
13-1#Z#04,06,07,09,18,22,28,32#172
Code: Select all
on mouseUp
put fld 1 into cntnr
replace tab with ",=," in cntnr
-- 19-2,=,Z,=,04,05,06,08,09,21,27,31,=,202
repeat with j=12 down to 5 --> 8 comma-items
sort cntnr numeric by item j of each
end repeat
replace ",=," with tab in cntnr
put cntnr into fld 1
end mouseUp
(USE "#" instead of tab here only to make it better visible)
14-1#Z#01,05,08,11,20,22,25,32#252
10-1#Z#02,03,08,11,18,24,25,31#207
19-2#Z#04,05,06,08,09,21,27,31#202
13-1#Z#04,06,07,09,18,22,28,32#172
shiftLock happens
Re: Sort
Hallo Hermann,[-hh] wrote:Is the itemdelimiter tab and you wish to sort lexicographically (co-sorted) numeric by the 8 comma-items of tab-item 3?
Few days ago, you asked me about the interest of using replaceText() in a sort command.
I believe this could be one area where it makes sense
Code: Select all
on mouseUp
put fld 1 into T
set the itemdelimiter to tab
sort lines of T numeric by replaceText( item 3 of each, comma, empty)
put T
end mouseUp
Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
-
- VIP Livecode Opensource Backer
- Posts: 2262
- Joined: Thu Feb 28, 2013 11:52 pm
- Location: Göttingen, DE
Re: Sort
Brilliant .
(Although the numbers must have, as it is here the case, the same length. That is, leading zeros where necessary. And no decimals and no negative numbers are allowed).
(Although the numbers must have, as it is here the case, the same length. That is, leading zeros where necessary. And no decimals and no negative numbers are allowed).
shiftLock happens
Re: Sort
[-hh] wrote:Brilliant .
Thanks to LiveCode for the sort command and its regex implementation....
True.(Although the numbers must have, as it is here the case, the same length.
That is, leading zeros where necessary. And no decimals and no negative numbers are allowed).
This solution is based, as usual, with the provided set of datas of the OP.
Other format of datas, another regex.
Regards,
Thierry
Last edited by Thierry on Tue May 23, 2017 1:58 pm, edited 1 time in total.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
-
- VIP Livecode Opensource Backer
- Posts: 2262
- Joined: Thu Feb 28, 2013 11:52 pm
- Location: Göttingen, DE
Re: Sort
Hi Thierry,
that would be good stuff for several minutes of a talk on 'regex etc.' with LiveCode Global 2017.
May I propose you as speaker?
"Basic and advanced examples of using regex within LiveCode script"
Would be very interesting.
that would be good stuff for several minutes of a talk on 'regex etc.' with LiveCode Global 2017.
May I propose you as speaker?
"Basic and advanced examples of using regex within LiveCode script"
Would be very interesting.
shiftLock happens
Re: Sort
Thanks Hermann for your ideas...[-hh] wrote:Hi Thierry,
May I propose you as speaker?
"Basic and advanced examples of using regex within LiveCode script"
Would be very interesting.
need to think about it.
Regards,
Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
-
- VIP Livecode Opensource Backer
- Posts: 9580
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Sort
Hi.
Lots of stuff going on here. But through it all, are you OK?
When you say "sort by item 3..." did you mean the third comma delimited item in the group of comma delimited items? That is, there are four "blocks" of data in your field, so the third item in line 1 would be "06". The way the list is ordered, that is the same item as if you only considered the middle block, which I suspect is what you were thinking. But even in that case, if your data stays in this format, you only need to:
Now this will sort, for example, "2" before "02", if that is OK. Otherwise you need more thinking.
Craig Newman
Lots of stuff going on here. But through it all, are you OK?
When you say "sort by item 3..." did you mean the third comma delimited item in the group of comma delimited items? That is, there are four "blocks" of data in your field, so the third item in line 1 would be "06". The way the list is ordered, that is the same item as if you only considered the middle block, which I suspect is what you were thinking. But even in that case, if your data stays in this format, you only need to:
Code: Select all
sort fld 1 numeric by item 3 of each
Craig Newman
-
- VIP Livecode Opensource Backer
- Posts: 9802
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: Sort
Given that the strings are padded with leading zeros for uniform length, do we need to explicitly coerce numeric evaluation? E.g. this would seem sufficient, no?:
Code: Select all
on mouseUp
set the itemdel to tab
sort lines of fld 1 by item 3 of each
end mouseUp
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Sort
As usual I nearly got there apart from a couple of things
now sorted.
I replaced tabs with commas but
---got "numeric" and "ascending" in the wrong order
---sorted from item 3 to 10 instead of 10 down to 3
Thank you all for your help.
My test stack is attached.
now sorted.
I replaced tabs with commas but
---got "numeric" and "ascending" in the wrong order
---sorted from item 3 to 10 instead of 10 down to 3
Thank you all for your help.
My test stack is attached.
- Attachments
-
- allSets Sort.zip
- (2.03 KiB) Downloaded 190 times
Is age an excuse? Eighty-four and counting.
Programming powered by coffee.
Programming powered by coffee.