SORT by length

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

SORT by length

** Clarence P Martin ** via use-livecode
I have a listField containing a number of words which I want to order so
the longest comes
first . . .

doing this:

sort lines of fld "myGuff" by length(each)

sorts the words, but the shortest one comes first...

Richmond.
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: SORT by length

** Clarence P Martin ** via use-livecode
From the dictionary entry for “sort”:
If you don't specify a direction, the sort is ascending.
One of the following items:
        • ascending -sorts in ascending order
        • descending -sorts in descending order

> On Aug 7, 2017, at 3:23 PM, Richmond Mathewson via use-livecode <[hidden email]> wrote:
>
> I have a listField containing a number of words which I want to order so the longest comes
> first . . .
>
> doing this:
>
> sort lines of fld "myGuff" by length(each)
>
> sorts the words, but the shortest one comes first…



_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: SORT by length

** Clarence P Martin ** via use-livecode
Thanks: that looks remarkably simple.

I suppose the "trick" is knowing which word to look up in the Dictionary ;-)

Richmond.

On 8/8/17 1:29 am, Jerry Jensen via use-livecode wrote:

>  From the dictionary entry for “sort”:
> If you don't specify a direction, the sort is ascending.
> One of the following items:
> • ascending -sorts in ascending order
> • descending -sorts in descending order
>
>> On Aug 7, 2017, at 3:23 PM, Richmond Mathewson via use-livecode <[hidden email]> wrote:
>>
>> I have a listField containing a number of words which I want to order so the longest comes
>> first . . .
>>
>> doing this:
>>
>> sort lines of fld "myGuff" by length(each)
>>
>> sorts the words, but the shortest one comes first…
>
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: SORT by length

** Clarence P Martin ** via use-livecode
In reply to this post by ** Clarence P Martin ** via use-livecode
That scr*wed up badly.

I found this: http://forums.livecode.com/viewtopic.php?f=9&t=10505#p48529

and modified it:

*on**mouseUp*

**

***put**empty **into**rSortByLength*

**

***put**fld "CL" **into**tText*

**

***repeat****for**each word tLine in tText*

**

***put**tLine&","
&**the****length****of**tLine&**return****after**rSortByLength*

**

***end****repeat*

**

***delete**char -1 **of**rSortByLength*

**

***sort**lines **of**rSortByLength descending numeric by item 2 **of**each*

**

***put**empty **into**fld "CL"*

**

***put**rSortByLength **into**fld "CL"*

**

***--*

**

***put**1 **into**KOUNT*

**

***repeat**until line KOUNT **of**fld "CL" is empty*

**

***delete****the**last char **of**line KOUNT **of**fld "CL"*

**

***delete****the**last char **of**line KOUNT **of**fld "CL"*

**

***add**1 **to**KOUNT*

**

***end****repeat*

**

*end**mouseUp*


Richmond.


On 8/8/17 1:29 am, Jerry Jensen via use-livecode wrote:

> From the dictionary entry for “sort”: If you don't specify a
> direction, the sort is ascending. One of the following items: •
> ascending -sorts in ascending order • descending -sorts in descending
> order
>> On Aug 7, 2017, at 3:23 PM, Richmond Mathewson via use-livecode
>> <[hidden email]> wrote: I have a listField containing
>> a number of words which I want to order so the longest comes first .
>> . . doing this: sort lines of fld "myGuff" by length(each) sorts the
>> words, but the shortest one comes first…
> _______________________________________________ use-livecode mailing
> list [hidden email] Please visit this url to subscribe,
> unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: SORT by length

** Clarence P Martin ** via use-livecode
So what did it do? With all those asterisks I can’t run it without retyping the whole thing.

> On Aug 7, 2017, at 3:42 PM, Richmond Mathewson via use-livecode <[hidden email]> wrote:
>
> That scr*wed up badly.
>
> I found this: http://forums.livecode.com/viewtopic.php?f=9&t=10505#p48529
>
> and modified it:
>
> *on**mouseUp*
>
> **
>
> ***put**empty **into**rSortByLength*
>
> **
>
> ***put**fld "CL" **into**tText*
>
> **
>
> ***repeat****for**each word tLine in tText*
>
> **
>
> ***put**tLine&"," &**the****length****of**tLine&**return****after**rSortByLength*
>
> **
>
> ***end****repeat*
>
> **
>
> ***delete**char -1 **of**rSortByLength*
>
> **
>
> ***sort**lines **of**rSortByLength descending numeric by item 2 **of**each*
>
> **
>
> ***put**empty **into**fld "CL"*
>
> **
>
> ***put**rSortByLength **into**fld "CL"*
>
> **
>
> ***--*
>
> **
>
> ***put**1 **into**KOUNT*
>
> **
>
> ***repeat**until line KOUNT **of**fld "CL" is empty*
>
> **
>
> ***delete****the**last char **of**line KOUNT **of**fld "CL"*
>
> **
>
> ***delete****the**last char **of**line KOUNT **of**fld "CL"*
>
> **
>
> ***add**1 **to**KOUNT*
>
> **
>
> ***end****repeat*
>
> **
>
> *end**mouseUp*
>
>
> Richmond.
>
>
> On 8/8/17 1:29 am, Jerry Jensen via use-livecode wrote:
>> From the dictionary entry for “sort”: If you don't specify a direction, the sort is ascending. One of the following items: • ascending -sorts in ascending order • descending -sorts in descending order
>>> On Aug 7, 2017, at 3:23 PM, Richmond Mathewson via use-livecode <[hidden email]> wrote: I have a listField containing a number of words which I want to order so the longest comes first . . . doing this: sort lines of fld "myGuff" by length(each) sorts the words, but the shortest one comes first…
>> _______________________________________________ use-livecode mailing list [hidden email] Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: SORT by length

** Clarence P Martin ** via use-livecode
In reply to this post by ** Clarence P Martin ** via use-livecode
sort lines of fld “myGuff” descending numeric by length(each) – should do it.

Terry...

On 8/08/2017 8:23 am, "use-livecode on behalf of Richmond Mathewson via use-livecode" <[hidden email] on behalf of [hidden email]> wrote:

    I have a listField containing a number of words which I want to order so
    the longest comes
    first . . .
   
    doing this:
   
    sort lines of fld "myGuff" by length(each)
   
    sorts the words, but the shortest one comes first...
   
    Richmond.
    _______________________________________________
    use-livecode mailing list
    [hidden email]
    Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
    http://lists.runrev.com/mailman/listinfo/use-livecode
   
   

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: SORT by length

** Clarence P Martin ** via use-livecode
In reply to this post by ** Clarence P Martin ** via use-livecode
Sorry about the asterisks . . .

That is what happens when one copy-pastes directly from the LiveCode
scriptEditor into
Thunderbird.

on mouseUp

put empty into rSortByLength

put fld "CL" into tText

repeat for each word tLine in tText

put tLine&"," &the length of tLine&return after rSortByLength

end repeat

delete char -1 of rSortByLength

sort lines of rSortByLength descending numeric by item 2 of each

put empty into fld "CL"

put rSortByLength into fld "CL"

--

put 1 into KOUNT

repeat until line KOUNT of fld "CL" is empty

delete the last char of line KOUNT of fld "CL"

delete the last char of line KOUNT of fld "CL"

add 1 to KOUNT

end repeat

end mouseUp



Richmond.
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: SORT by length

** Clarence P Martin ** via use-livecode
In reply to this post by ** Clarence P Martin ** via use-livecode
> Richmond wrote:
> Sorry about the asterisks . . .
> That is what happens when one copy-pastes directly from the LiveCode
> scriptEditor into Thunderbird.

Specify the default character encodings for sending and receiving messages
Menu location: Thunderbird > Preferences > Display > Formatting - Advanced button

@Sort by length

As several others said:
     sort str [ascending|descending] numeric by length(each)
works perfectly.

But the first part of your script sorts correctly numeric by length if and only if
there is NO COMMA in the string to sort ... You sort by item 2, of course you could
sort by item -1.

Nevertheless the one-liner above will be *much* faster.

> Richmond wrote:
> on mouseUp
>   put empty into rSortByLength
>   put fld "CL" into tText
>   repeat for each word tLine in tText
>     put tLine&"," &the length of tLine&return after rSortByLength
>   end repeat
>   delete char -1 of rSortByLength
>   sort lines of rSortByLength descending numeric by item 2 of each
>   put empty into fld "CL"
>   put rSortByLength into fld "CL"
>   --
>   put 1 into KOUNT
>   repeat until line KOUNT of fld "CL" is empty
>     delete the last char of line KOUNT of fld "CL"
>     delete the last char of line KOUNT of fld "CL"
>     add 1 to KOUNT
>   end repeat
> end mouseUp

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: SORT by length

** Clarence P Martin ** via use-livecode
In reply to this post by ** Clarence P Martin ** via use-livecode
Paste it into a text only text editor first and you won't get the double line breaks either.

Bob S


> On Aug 8, 2017, at 01:46 , Richmond Mathewson via use-livecode <[hidden email]> wrote:
>
> Sorry about the asterisks . . .
>
> That is what happens when one copy-pastes directly from the LiveCode scriptEditor into
> Thunderbird.
>
> on mouseUp
>
> put empty into rSortByLength


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: SORT by length

** Clarence P Martin ** via use-livecode
On 08/08/2017 07:39 AM, Bob Sneidar via use-livecode wrote:
> Paste it into a text only text editor first and you won't get the double line breaks either.

I paste from LC directly into Thunderbird regularly.
Look in the Preferences | Composition pane
There's an option at the bottom for "Configure text format behavior"
with a button for "Send Options..."

You'll find a checkbox for "Send messages as plain text if possible" as
well as a box where you can whitelist the listserv domain for plain text.

--
  Mark Wieder
  [hidden email]

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: SORT by length

** Clarence P Martin ** via use-livecode
On my Mac I get double line breaks when I paste into Apple Mail. The prefs are already set to plain text, so I am not sure why I am still getting the double line breaks. In TextEdit I get single line breaks. Obviously the text editor understands that I didn't really mean cr/lf (or whatever is actually being copied). Apple Mail is not making any assumptions.

Seems to me that this is different behavior from V6 and earlier. This started with the unicode updates.

Bob S


> On Aug 8, 2017, at 08:46 , Mark Wieder via use-livecode <[hidden email]> wrote:
>
> On 08/08/2017 07:39 AM, Bob Sneidar via use-livecode wrote:
>> Paste it into a text only text editor first and you won't get the double line breaks either.
>
> I paste from LC directly into Thunderbird regularly.
> Look in the Preferences | Composition pane
> There's an option at the bottom for "Configure text format behavior" with a button for "Send Options..."
>
> You'll find a checkbox for "Send messages as plain text if possible" as well as a box where you can whitelist the listserv domain for plain text.
>
> --
> Mark Wieder
> [hidden email]


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: SORT by length

** Clarence P Martin ** via use-livecode
@Bob this is a bug, introduced in LC 8:

http://quality.livecode.com/show_bug.cgi?id=18699

On Tue, Aug 8, 2017 at 4:52 PM, Bob Sneidar via use-livecode <
[hidden email]> wrote:

> On my Mac I get double line breaks when I paste into Apple Mail. The prefs
> are already set to plain text, so I am not sure why I am still getting the
> double line breaks. In TextEdit I get single line breaks. Obviously the
> text editor understands that I didn't really mean cr/lf (or whatever is
> actually being copied). Apple Mail is not making any assumptions.
>
> Seems to me that this is different behavior from V6 and earlier. This
> started with the unicode updates.
>
> Bob S
>
>
> > On Aug 8, 2017, at 08:46 , Mark Wieder via use-livecode <
> [hidden email]> wrote:
> >
> > On 08/08/2017 07:39 AM, Bob Sneidar via use-livecode wrote:
> >> Paste it into a text only text editor first and you won't get the
> double line breaks either.
> >
> > I paste from LC directly into Thunderbird regularly.
> > Look in the Preferences | Composition pane
> > There's an option at the bottom for "Configure text format behavior"
> with a button for "Send Options..."
> >
> > You'll find a checkbox for "Send messages as plain text if possible" as
> well as a box where you can whitelist the listserv domain for plain text.
> >
> > --
> > Mark Wieder
> > [hidden email]
>
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Loading...