{"identifier":48574,"topic":"","name":"sort 2","text":"The last form of the<code> sort <\/code>command (<code>by <i>expression<\/i><\/code> )<code> <\/code>sorts lines or items of a container by any expression. If you don\u2019t specify,<code> sort <\/code>orders by lines.  Before<code> <i>expression<\/i> <\/code>is evaluated for each line or item of the container, the local variable<code> each <\/code>is set to the contents of the chunk. (Click the Examples button to see syntax examples using<code> each<\/code>.) <br><br>\n\n For all forms of the<code> sort <\/code>command, the default sort direction is<code> ascending, <\/code>and the default sort style is<code> text<\/code>. <br>\n<br>\nSort direction<code> ascending <\/code>orders the sort elements\u2014the value of the expression on each card or the lines or items in the container\u2014from lower to higher values. <br><br>\n\n Sort direction<code> descending <\/code>orders the sort elements from higher to lower values. <br><br>\n\n Sort style<code> text <\/code>compares the sort elements based on their ASCII values:  <br><br>\n\n <code>\"1\" < \"101\" < \"2\" < \"a\" < \"ab\" < \"b\"<\/code> <br>\n","related":{"41060":"mark"},"examples":"-- Sort a container:\n\nsort lines of card field 1\nsort items of card field 1\nsort lines of myVariable descending numeric\nsort items of Message box\nsort lines of the selection\nsort lines of field 1 by last word of each -- by last word of each line\nsort items of fld 1 descending numeric by word 2 of each\nsort items of myList by the random of 2000 -- reorder myList randomly\nsort lines of fld 1 numeric by length(cd fld each) -- if field 1\n            -- contains names of cd flds, orders names according \n            -- to number of characters in each field.\n\n-- Sort cards:\n\nsort by bkgnd field \"Name\"\nsort this stack by bkgnd field \"Name\"\nsort stack by bkgnd field \"Name\"\nsort marked cards of this stack by bkgnd field \"Name\"\n\nsort this background by bkgnd field \"Name\"\nsort background 2 by bkgnd field \"Name\"\nsort marked cards of previous background by bkgnd field \"Name\"\n\nsort descending by bkgnd field \"Name\"\nsort descending international by bkgnd field \"Name\"\n\nsort numeric by bkgnd field 2\nsort numeric by the id of this card\n\nsort by (bkgnd field \"Last Name\" & bkgnd field \"First Name\")\nsort by mySortFunction()","demo":"","debug":{"9":["The last form of the"],"10":["Sort direction ascen"]}}