Sorting comma delimited items on one line
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Sorting comma delimited items on one line
I have been trying to sort 10 comma delimited numbers on one line ,lowest to highest.
I have put the line of comma delimited number into a variable (call it mop) and tried:
sort mop numeric
or:
sort mop numeric ascending.
I thought I had used this years ago, but it seems not.
Every article I have read seems to me to be dealing with lines in a field.
I am feeling even more thickheaded than usual with this.
I have put the line of comma delimited number into a variable (call it mop) and tried:
sort mop numeric
or:
sort mop numeric ascending.
I thought I had used this years ago, but it seems not.
Every article I have read seems to me to be dealing with lines in a field.
I am feeling even more thickheaded than usual with this.
Re: Sorting comma delimited items on one line
Code: Select all
replace comma with return in mop
sort mop numeric
replace return with comma in mop
Andreas Bergendal
Independent app and system developer
Free LC dev tools: https://github.com/wheninspace
(WIS_WebDeployHelper, WIS_ScriptDependencies, WIS_BrowserAnimation)
WhenInSpace: https://wheninspace.com
Independent app and system developer
Free LC dev tools: https://github.com/wheninspace
(WIS_WebDeployHelper, WIS_ScriptDependencies, WIS_BrowserAnimation)
WhenInSpace: https://wheninspace.com
Re: Sorting comma delimited items on one line
The dictionary does specify the syntax you need, and the various options.
sort [{lines | items} of] container [direction] [sortType] [by sortKey ]
If you leave out the chunk type, LC will expect you to mean "lines". For another chunk type, just use it in the statement.
Dictionary example:
local tNumbers
put "5,4,3,2,1" into tNumbers
sort items of tNumbers ascending numeric -- 5,4,3,2,1 becomes 1,2,3,4,5
sort [{lines | items} of] container [direction] [sortType] [by sortKey ]
If you leave out the chunk type, LC will expect you to mean "lines". For another chunk type, just use it in the statement.
Dictionary example:
local tNumbers
put "5,4,3,2,1" into tNumbers
sort items of tNumbers ascending numeric -- 5,4,3,2,1 becomes 1,2,3,4,5
Re: Sorting comma delimited items on one line
Sorry, but I have trouble making sense of the way things are answered in the dictionary.
This for instance seems reading another language:
sort [{lines | items} of] container [direction] [sortType] [by sortKey ]
But both of you solutions worked fine, and I do thank you both for the answers.
This for instance seems reading another language:
sort [{lines | items} of] container [direction] [sortType] [by sortKey ]
But both of you solutions worked fine, and I do thank you both for the answers.
-
- VIP Livecode Opensource Backer
- Posts: 10043
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Sorting comma delimited items on one line
For historical reasons, LC docs use a simplified variant of the Backus–Naur form (BNF) of syntax definition, where:
- Brackets ("[" and "]") enclose optional clauses.
- Vertical pipe ("|") means "or".
- Curly braces ("{" and "}") enclose options where at least one is required.
I believe these and other conventions used in the syntax guides are described in the User Guide (accessible through an item near the top of the Help menu), and may also be included in the API Dictionary itself. I'm not at a computer right now so I can't point to the precise location of that explanation, but the User Guide's Table of Contents is pretty good and should point the way to definitions for such conventions used throughout LC docs.
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: Sorting comma delimited items on one line
What everyone said.
So, in "mop", do you indeed have a series of numbers separated by commas on a single line? Like "204,21,42,99"? If so, and I bet you already have gotten this, but just to make sure, you would:
Remember that you can add "descending" if you need to, but "ascending" is the default, so the sort will start with the lowest
Craig
So, in "mop", do you indeed have a series of numbers separated by commas on a single line? Like "204,21,42,99"? If so, and I bet you already have gotten this, but just to make sure, you would:
Code: Select all
sort items of mop numeric
Craig