Quantcast

Sort so that "Hello" is always before "hello"

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

Sort so that "Hello" is always before "hello"

Richmond Mathewson via use-livecode
I have the following lines when a list of words is sorted:

Hello
hello
Hello
hello
hello

so there is no hierarchy between upper and lower case chars. I want caps to
go first. How do i do that pls?

--
Kaveh Bazargan
Director
River Valley Technologies
@kaveh1000
+44 7771 824 111
www.rivervalleytechnologies.com
_______________________________________________
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 so that "Hello" is always before "hello"

Richmond Mathewson via use-livecode
"set the caseSensitive to true" before sorting.

Phil Davis



On 5/18/17 10:10 AM, Kaveh Bazargan via use-livecode wrote:

> I have the following lines when a list of words is sorted:
>
> Hello
> hello
> Hello
> hello
> hello
>
> so there is no hierarchy between upper and lower case chars. I want caps to
> go first. How do i do that pls?
>

--
Phil Davis


_______________________________________________
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 so that "Hello" is always before "hello"

Richmond Mathewson via use-livecode
In reply to this post by Richmond Mathewson via use-livecode
doesn't look like there is a command to do this. Try creating an sqLite database in memory (or on disk it doesn't matter) called tempdata with a column called textdata, adding your words/items/lines to the database, then query the database with select textdata from template order by textdata.

You could create this as a function passing the arguments pText, pChunkType, pOrder. pText contains your text to be sorted, pChunkType could be lines, items or words, and pOrder would be ascending or descending.

Presto! Your own case sensitive sort function!

Bob S




> On May 18, 2017, at 10:10 , Kaveh Bazargan via use-livecode <[hidden email]> wrote:
>
> I have the following lines when a list of words is sorted:
>
> Hello
> hello
> Hello
> hello
> hello
>
> so there is no hierarchy between upper and lower case chars. I want caps to
> go first. How do i do that pls?
>
> --
> Kaveh Bazargan
> Director
> River Valley Technologies
> @kaveh1000
> +44 7771 824 111
> www.rivervalleytechnologies.com


_______________________________________________
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 so that "Hello" is always before "hello"

dunbarx
The "caseSensitive" is a global property. It can be set like any other. if you do so before the "sort" command, the capital first letters precede the lower case.

Craig
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Sort so that "Hello" is always before "hello"

Richmond Mathewson via use-livecode
Oh right. I forgot about that. Still, I like my way better. ;-)

Bob S


> On May 18, 2017, at 13:30 , dunbarx via use-livecode <[hidden email]> wrote:
>
> The "caseSensitive" is a global property. It can be set like any other. if
> you do so before the "sort" command, the capital first letters precede the
> lower case.
>
> Craig


_______________________________________________
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 so that "Hello" is always before "hello"

Richmond Mathewson via use-livecode
In reply to this post by Richmond Mathewson via use-livecode
Thanks Phil

That works in the case I mentioned, but with different letters, All upper
case chars come to top, so I get:

Goodbye
Hello
goodbye
hello

What I need is

Goodbye
goodbye
Hello
hello


On 18 May 2017 at 18:19, Phil Davis via use-livecode <
[hidden email]> wrote:

> "set the caseSensitive to true" before sorting.
>
> Phil Davis
>
>
>
> On 5/18/17 10:10 AM, Kaveh Bazargan via use-livecode wrote:
>
>> I have the following lines when a list of words is sorted:
>>
>> Hello
>> hello
>> Hello
>> hello
>> hello
>>
>> so there is no hierarchy between upper and lower case chars. I want caps
>> to
>> go first. How do i do that pls?
>>
>>
> --
> Phil Davis
>
>
> _______________________________________________
> 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
>



--
Kaveh Bazargan
Director
River Valley Technologies
@kaveh1000
+44 7771 824 111
www.rivervalleytechnologies.com
_______________________________________________
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 so that "Hello" is always before "hello"

Richmond Mathewson via use-livecode
Then that is not a sort!

Bob S


> On May 18, 2017, at 14:13 , Kaveh Bazargan via use-livecode <[hidden email]> wrote:
>
> Thanks Phil
>
> That works in the case I mentioned, but with different letters, All upper
> case chars come to top, so I get:
>
> Goodbye
> Hello
> goodbye
> hello
>
> What I need is
>
> Goodbye
> goodbye
> Hello
> hello
>
>
> On 18 May 2017 at 18:19, Phil Davis via 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 so that "Hello" is always before "hello"

Richmond Mathewson via use-livecode
What you are wanting to do is a recursive function that sorts within each word. If the first character is all you care about, it would be easy enought to code, but if *every* character comes into play, the problem becomes grossly complex. This isn't a sort problem. It's a filing order problem.

Bob S


> On May 18, 2017, at 14:15 , Bob Sneidar <[hidden email]> wrote:
>
> Then that is not a sort!
>
> Bob S
>
>
>> On May 18, 2017, at 14:13 , Kaveh Bazargan via use-livecode <[hidden email]> wrote:
>>
>> Thanks Phil
>>
>> That works in the case I mentioned, but with different letters, All upper
>> case chars come to top, so I get:
>>
>> Goodbye
>> Hello
>> goodbye
>> hello
>>
>> What I need is
>>
>> Goodbye
>> goodbye
>> Hello
>> hello
>>
>>
>> On 18 May 2017 at 18:19, Phil Davis via 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 so that "Hello" is always before "hello"

Richmond Mathewson via use-livecode
In reply to this post by Richmond Mathewson via use-livecode
You want a sort with co-sort:

set the casesensitive to true -- secondary sort:
sort myContainer
set the casesensitive to false -- primary sort:
sort myContainer

_______________________________________________
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 so that "Hello" is always before "hello"

Richmond Mathewson via use-livecode
In reply to this post by Richmond Mathewson via use-livecode
> Kaveh B. wrote:
> I have the following lines when a list of words is sorted: Hello
> hello Hello hello hello so there is no hierarchy between upper and
> lower case chars. I want caps to go first. How do i do that pls?

Let me explain a bit more.

You want a sort with co-sort. LC allows this because it's sort is stable:

The secondary sort or 'co-sort' has to be done before the sort. It sets the
sort order for the case that chunks in the following primary sort function.

Here are first all upper case chunks sorted before the lower case chunks.
Then, with casesensitive false, LC doesn't change the sort order for
chunks that are equal in the current sort function.

on mouseUp
  set the casesensitive to true -- secondary sort:
  sort myContainer
  set the casesensitive to false -- primary sort:
  sort myContainer
on mouseUp

For example

Hello
hello
hello
hallo
Hallo
Guest
guest
Guest

becomes

Guest
Guest
guest
Hallo
hallo
Hello
hello
hello


_______________________________________________
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 so that "Hello" is always before "hello"

Richmond Mathewson via use-livecode
In reply to this post by Richmond Mathewson via use-livecode
On Thu, May 18, 2017 at 2:20 PM, Bob Sneidar via use-livecode <
[hidden email]> wrote:

> What you are wanting to do is a recursive function that sorts within each
> word. If the first character is all you care about, it would be easy
> enought to code, but if *every* character comes into play, the problem
> becomes grossly complex. This isn't a sort problem. It's a filing order
> problem


so

sort the lines of mycontainer by mysort of each


where mysort is a function previously defined.

Or, perhaps more creatively

repeat for each line theLin in theData

put theLin into arry[mysort(theLin)

end repeat

put the keys of arry into srtVals

sort lines of srtVals

repeat for each line theLin in srtVals

put arry[theLin] & cr after newData

end repeat


where mysort() simply rearranges the characters into order AaBb etc.  (so
"A" maps to "a", "a" maps to "b", and so forth, leaving the rest of the
ascii intact.  Or perhaps it could remap the symbols & numbers to
preference, too.   There are something like 95! possible mappings . . .

--
Dr. Richard E. Hawkins, Esq.
(702) 508-8462
_______________________________________________
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 so that "Hello" is always before "hello"

Richmond Mathewson via use-livecode
In reply to this post by Richmond Mathewson via use-livecode
On Thu, May 18, 2017 at 2:43 PM, hh via use-livecode <
[hidden email]> wrote:

> on mouseUp
>   set the casesensitive to true -- secondary sort:
>   sort myContainer
>   set the casesensitive to false -- primary sort:
>   sort myContainer
> on mouseUp
>

Now *that* is clever.

At first I read you as having a slew of containers, which led to the
possibility of something like

sort lines of theData by word 1 of each & (lower(char 1 of each) <>
upper(char 1 of each))


But I don't think I can use multiple each's like that, can I?


--
Dr. Richard E. Hawkins, Esq.
(702) 508-8462
_______________________________________________
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 so that "Hello" is always before "hello"

Richmond Mathewson via use-livecode
In reply to this post by Richmond Mathewson via use-livecode
Brilliant, thank you. I have tried to fall out of love with LiveCode but it
is hard!

I used HyperCard since pre-release version ;-)

On 18 May 2017 at 22:28, hh via use-livecode <[hidden email]>
wrote:

> You want a sort with co-sort:
>
> set the casesensitive to true -- secondary sort:
> sort myContainer
> set the casesensitive to false -- primary sort:
> sort myContainer
>
> _______________________________________________
> 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
>



--
Kaveh Bazargan
Director
River Valley Technologies
@kaveh1000
+44 7771 824 111
www.rivervalleytechnologies.com
_______________________________________________
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 so that "Hello" is always before "hello"

Richmond Mathewson via use-livecode
In reply to this post by Richmond Mathewson via use-livecode
> Richard E.H. wrote:
> ... the possibility of something like
>
>   sort lines of theData by word 1 of each & \
>     (lower(char 1 of each) <> upper(char 1 of each))
>
> But I don't think I can use multiple each's like that, can I?

Your approach is to use a sort function, a powerful tool.

The multiple "each" are no problem. "Each" points simply to the current line.
But because lower(a-zA-Z) is _always_ not equal to upper(a-zA-Z) you mean probably

set the casesensitive to false -- is default, just to be clear here
sort theData by each & \
   ( charToNum(char 1 of each) <> charToNum(lower(char 1 of each)) )

Then you have (each & "false") if char 1 of each is an upper case what comes
in the ascending order before (each & "true").

[But this will be, TMHO, usually a bit slower than multiple sorts].



_______________________________________________
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 so that "Hello" is always before "hello"

Richmond Mathewson via use-livecode
In reply to this post by Richmond Mathewson via use-livecode
Correction, sorry.

> I wrote:
> But because lower(a-zA-Z) is _always_ not equal to upper(a-zA-Z) ...

This handles only one case of casesensitivity. Should read:

If the casesensitive is true then
lower(a-zA-Z) is _always_ not equal to upper(a-zA-Z)

If the casesensitive is false then
lower(a-zA-Z) is _always_ equal to upper(a-zA-Z)

[So this gives no further distinction for sorting.]

_______________________________________________
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 so that "Hello" is always before "hello"

Richmond Mathewson via use-livecode
A slight variation from Hermann's code,
working *only* with ASCII:


sort lines of T numeric by AaZz_sort( each)


function AaZz_sort x
   get chartonum( char 1 of x)
   if IT > 96 then return ( IT - 96) * 2 + 1
   else return ( IT - 64) * 2
end AaZz_sort


I can explain if someone is asking for...

and I have no ideas if the double-sort is faster then this one.


Thierry

------------------------------------------------
Thierry Douez - sunny-tdz.com
sunnYrex - sunnYtext2speech - sunnYperl - sunnYmidi - sunnYmage
_______________________________________________
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 so that "Hello" is always before "hello"

Richmond Mathewson via use-livecode
In reply to this post by Richmond Mathewson via use-livecode
> Thierry wrote:
> sort lines of T numeric by AaZz_sort( each)
> function AaZz_sort x
>    get chartonum( char 1 of x)
>    if IT > 96 then return ( IT - 96) * 2 + 1
>    else return ( IT - 64) * 2
> end AaZz_sort


Hi Thierry,

don't you need a second sort as 'primary' sort?

sort lines of T numeric by each & AaZz_sort( each) ?
sort lines of T

Else the container is sorted by the first char of each line only.

But your ASCII-number-formula for uppercase/lowercase A-Za-z
ordering is really worth to go in a lib!

Hermann

By the way, my "solution" is the following, that handles uppercase
char before lowercase char sorting for each char of the lines.

  set the casesensitive to true -- secondary sort:
  sort myContainer
  set the casesensitive to false -- primary sort:
  sort myContainer


_______________________________________________
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 so that "Hello" is always before "hello"

Richmond Mathewson via use-livecode
2017-05-19 15:44 GMT+02:00 hh
​:

> Thierry wrote:
> > sort lines of T numeric by AaZz_sort( each)
> > function AaZz_sort x
> >    get chartonum( char 1 of x)
> >    if IT > 96 then return ( IT - 96) * 2 + 1
> >    else return ( IT - 64) * 2
> > end AaZz_sort
>
>
> Hi Thierry,
>
> don't you need a second sort as 'primary' sort?
>

​Mmm, no ?
I thought that was the question from the OP... misreading  :)


>
> sort lines of T numeric by each & AaZz_sort( each) ?
> sort lines of T
>
> Else the container is sorted by the first char of each line only.
>

​Yes, you are right, so I rewrite it a bit to be more *readable*:


sort lines of T numeric by AaZz_sort(char 1 of each)

function AaZz_sort x
   get chartonum( x)
   if IT > 96 then return ( IT - 96) * 2 + 1
   else return ( IT - 64) * 2
end AaZz_sort



> But your ASCII-number-formula for uppercase/lowercase A-Za-z
> ordering is really worth to go in a lib!
>
> Hermann
>
> By the way, my "solution" is the following, that handles uppercase
> char before lowercase char sorting for each char of the lines.
>
>   set the casesensitive to true -- secondary sort:
>   sort myContainer
>   set the casesensitive to false -- primary sort:
>   sort myContainer
>
>
​I'll try to come up with something else later...

Thierry​

--
------------------------------------------------
Thierry Douez - sunny-tdz.com
sunnYrex - sunnYtext2speech - sunnYperl - sunnYmidi - sunnYmage
_______________________________________________
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 so that "Hello" is always before "hello"

Richmond Mathewson via use-livecode
​Hallo Hermann,


>
>> sort lines of T numeric by each & AaZz_sort( each) ?
>> sort lines of T
>>
>> Else the container is sorted by the first char of each line only.
>>
>
>
​Ok, I can't find a way to do it with a single sort.

Therefore your solution 1st or mine adding a
second sort after it.

Enjoy your week-ed,

Thierry


​Yes, you are right, so I rewrite it a bit to be more *readable*:

>
>
> sort lines of T numeric by AaZz_sort(char 1 of each)
>
> function AaZz_sort x
>    get chartonum( x)
>    if IT > 96 then return ( IT - 96) * 2 + 1
>    else return ( IT - 64) * 2
> end AaZz_sort
> ​
>

--
------------------------------------------------
Thierry Douez - sunny-tdz.com
sunnYrex - sunnYtext2speech - sunnYperl - sunnYmidi - sunnYmage
_______________________________________________
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 so that "Hello" is always before "hello"

Richmond Mathewson via use-livecode
In reply to this post by Richmond Mathewson via use-livecode
Thierry,

out of interest, for a lazy day:
Have you ever thought of a sort function of type

sort by replaceText(each,...) ?

Must have a series of really good applications.
For example if one wishes, not for the container, but for
the sort only, to exchange several chars.

Hermann

_______________________________________________
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...