Hi all
As the title says how can i sort a list casesensitive ? What is the use of the casesensitive in sort list?
Thanks in advance from from record4
sort(list, casesensitive, natural)
Moderator: Martin
sort(list, casesensitive, natural)
No.1 Automation app in play store Automagic Premium
Samsung Galaxy j2 non rooted.
Android 5.1.1
Samsung Galaxy j2 non rooted.
Android 5.1.1
Re: sort(list, casesensitive, natural)
I made a test:
l = newList("Y", "n", "a", "N", "y", "n", "A", "Y", "a");
a = sort(copyList(l), false, false);
b = sort(copyList(l), false, true);
c = sort(copyList(l), true, false);
d = sort(copyList(l), true, true);
// sort(list, casesensitive, natural)
And I got the result:
Code: Select all
l = [Y, n, a, N, y, n, A, Y, a]
a = [a, A, a, n, N, n, Y, y, Y]
b = [a, A, a, n, N, n, Y, y, Y]
c = [A, N, Y, Y, a, a, n, n, y]
d = [a, a, A, n, n, N, y, Y, Y]
So, I concluded:
- if (casesensitive == false and (natural == false or natural == true)):
- Case of variables: a and b
- List is sorted "a to z" but Upper case letters are treated as lower case letters (while preserving order of corresponding letters).
- if (casesensitive == true and natural == false):
- Case of variable: c
- List is sorted "A to Z to a to z" (all Upper case letters stand before all lower case letters).
- if (casesensitive == true and natural == true):
- Case of variable: d
- List is sorted "a(A) to z(Z)" (Upper case letters are treated as lower case letters but each Upper case letter must stands after all its corresponding lower case letters).
How do you think?
Re: sort(list, casesensitive, natural)
case sensitive as the name stated, differentiate between upper case and lower case. For AM, the case sensitive option is affected by the natural sort.
Case sensitive + natural = lower case first
Case sensitive + lexical = Upper case first
While natural (natural true) means the human nature of understanding number. Multiple numbers will be grouped together to be sorted. When natural is changed to false, means it is lexical order, the machine way of understanding number. It takes 1 digit by 1 digit, it compare up to the ASCII code. The reason why case sensitive when used with lexical give upper case first, because ASCII code of 'A' is 65 (hex 41) and 'a' is 97 (hex 61). So upper case has lower number, appear first.
This is natural for human
While this is natural to machine (lexical)
To test it, here is the code. Use debug dialog or message dialog with {show} to check.
- As you can see, a and d has the same result. Means, omitting the option, sort(list), will default to false, true //case insensitive, natural
- in "b. true, true : Case Sensitive, Natural", lower case "image" will get the first place. Then, between 7 and 069, since it is natural sort, 7 < 69, so 7 come first. The same with the "Image", 9 < 42, so 9 come first
- in "c. true, false : Case Sensitive, Lexical", because lexical means ASCII code, "Image" will come first. The 0789 and 345, the first digit of 0789 is 0, while 345 is 3. That's why 0 come first, hence 0789 is above 345. The same with 069 vs 7, first digit 0 vs 7, 069 is above.
- d is the default option we want to use most of the time, case insensitive and natural
- in "e. false, false : Case Insensitive, Lexical", since it is not case sensitive, the only thing matters is the number. Number with first digit 0 will come first. hence 069 and 0789. 7 and 9 despite being the lowest number, come last.
In most cases, you want to use "d. false, true : Case Insensitive, Natural", which is already the default option.
Case sensitive + natural = lower case first
Case sensitive + lexical = Upper case first
While natural (natural true) means the human nature of understanding number. Multiple numbers will be grouped together to be sorted. When natural is changed to false, means it is lexical order, the machine way of understanding number. It takes 1 digit by 1 digit, it compare up to the ASCII code. The reason why case sensitive when used with lexical give upper case first, because ASCII code of 'A' is 65 (hex 41) and 'a' is 97 (hex 61). So upper case has lower number, appear first.
This is natural for human
Code: Select all
a1.txt
a2.txt
a3.txt
a4.txt
a5.txt
a6.txt
a7.txt
a8.txt
a9.txt
a10.txt
a11.txt
a12.txt
a100.txt
a101.txt
Code: Select all
a1.txt
a10.txt
a100.txt
a101.txt
a11.txt
a12.txt
a2.txt
a3.txt
a4.txt
a5.txt
a6.txt
a7.txt
a8.txt
a9.txt
To test it, here is the code. Use debug dialog or message dialog with {show} to check.
Code: Select all
list = newList(
"Image 42",
"image 7",
"Image 9",
"image 069",
"Image 345",
"Image 0789");
a = sort(copyList(list)); //default is case insensitive, natural
b = sort(copyList(list), true, true); //case sensitive, natural
c = sort(copyList(list), true, false); //case sensitive, lexical
d = sort(copyList(list), false, true); //case insensitive, natural
e = sort(copyList(list), false, false); //case insensitive, lexical
show = "a. Default : Case Insensitive, Natural\n{a,listformat}\n\n" +
"b. true, true : Case Sensitive, Natural\n{b,listformat}\n\n" +
"c. true, false : Case Sensitive, Lexical\n{c,listformat}\n\n" +
"d. false, true : Case Insensitive, Natural\n{d,listformat}\n\n" +
"e. false, false : Case Insensitive, Lexical\n{e,listformat}\n\n";
- in "b. true, true : Case Sensitive, Natural", lower case "image" will get the first place. Then, between 7 and 069, since it is natural sort, 7 < 69, so 7 come first. The same with the "Image", 9 < 42, so 9 come first
- in "c. true, false : Case Sensitive, Lexical", because lexical means ASCII code, "Image" will come first. The 0789 and 345, the first digit of 0789 is 0, while 345 is 3. That's why 0 come first, hence 0789 is above 345. The same with 069 vs 7, first digit 0 vs 7, 069 is above.
- d is the default option we want to use most of the time, case insensitive and natural
- in "e. false, false : Case Insensitive, Lexical", since it is not case sensitive, the only thing matters is the number. Number with first digit 0 will come first. hence 069 and 0789. 7 and 9 despite being the lowest number, come last.
In most cases, you want to use "d. false, true : Case Insensitive, Natural", which is already the default option.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.