Different Sort of Sort

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
RossG
Posts: 247
Joined: Thu Jan 08, 2015 7:38 am

Different Sort of Sort

Post by RossG » Sun May 22, 2016 7:34 pm

I have lines in a field:

1 BHO
4 RLO
6 BHE

etc.

Is there a way to sort them on item 2?
Is age an excuse? Eighty-four and counting.
Programming powered by coffee.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10330
Joined: Wed May 06, 2009 2:28 pm

Re: Different Sort of Sort

Post by dunbarx » Sun May 22, 2016 9:33 pm

Hi.

Yes.

But I do not see the items. If you had:

cat,dog
deer,ticks
night,day

And did this:

Code: Select all

sort thatList by item 2 of each
Would give you:

night,day
cat,dog
deer,ticks

Read up on the sort command in the dictionary.

Craig Newman

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Different Sort of Sort

Post by Klaus » Mon May 23, 2016 11:55 am

If it HAS to be ITEMS:
...
set itemdel to SPACE
sort lines of fld X by item 2 of each
...
If NOT:
...
sort lines of fld X by WORD 2 of each
...
8)

RossG
Posts: 247
Joined: Thu Jan 08, 2015 7:38 am

Re: Different Sort of Sort

Post by RossG » Thu May 26, 2016 4:58 pm

Klaus

I was thinking of a function from my FoxPro days:

char to ASCII

ASCII to char.

The only place I see ASCII mentioned in the
Dictionary is in reference to sorting (I think).
Is age an excuse? Eighty-four and counting.
Programming powered by coffee.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10099
Joined: Fri Feb 19, 2010 10:17 am

Re: Different Sort of Sort

Post by richmond62 » Thu May 26, 2016 5:08 pm

Well I made a stack as per your recipe and put THIS in my button [I called my listField "ff"]:

on mouseUp
sort fld "ff" by char 2 of each
end mouseUp

and it sorted the items by the second letter.

The only potential snag is that it put those 3 items
in lines 4,5 and 6 of the field.

Of course IFF you are using Unicode characters things will get a bit more awkward.

MaxV
Posts: 1580
Joined: Tue May 28, 2013 2:20 pm
Contact:

Re: Different Sort of Sort

Post by MaxV » Wed Jun 08, 2016 4:14 pm

Code: Select all

sort field 1 by word 2 of each
It works, moreover you can do more complex sorting, but always start from right ( http://livecode.wikia.com/wiki/Sorting )
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

Post Reply