sorting question

Kay C Lan lan.kc.macmail at gmail.com
Fri Sep 26 04:30:15 EDT 2014


On Wed, Sep 24, 2014 at 4:40 PM, Dave Kilroy
<dave at applicationinsight.com> wrote:
> For others wondering what the cause was, it was likely that the spaces in
> each item were confusing things

It is impossible that the spaces in front of each item could cause the
sort NOT to change the list at all, which is what Larry reported.

In the message box:

put " ID, NA, OD, OA, FE" into tStore
   sort items of tStore
put tStore into msg

The space character is just another character and LC will sort it correctly.

Of the list given, only the first item may not have had a space in
front of it, so this may have ended up in the wrong place but the rest
should have sorted correctly. Whilst removing and replacing spaces is
one option to correct this, it may not be suitable in every situation,
especially if the existence or lack of a space has significance - i.e.
if you have a list of file names and you are specifically looking for
those names that have a space as a prefix or a suffix.

put "ID, NA , OD,OA, FE" into tStore
   sort items of tStore
put tStore into msg

Will correctly sort the file names placing all those with a prefix
space at the beginning and preserving all suffix spaces.

If prefix and suffix spaces are irrelevant then you can save yourself
the hassle of standardising your data by removing and replacing the
spaces by simply specifying that you want to sort by word:

put "ID, NA , OD,OA, FE" into tStore
  sort items of tStore by word 1 of each
put tStore into msg




More information about the use-livecode mailing list