AnsweredAssumed Answered

Sort questions

Question asked by VRFuser on Jun 4, 1999
Barrie Walden <bwalden@whoi.edu> wrote:
> Hi folks,
>
> I'm looking for suggestions for a pair of sorting problems. I have a
> text array similar to [COM9, COM100, COM8, COM20] and I want the sorted
> array to be [COM8, COM9, COM20, COM100]. Sort() results in [COM100,
> COM20, COM8, COM9] because it stops looking at characters in each string
> as soon as possible (ASCII sort).
>
>
> Both of these problems can be handled with some resonably complicated
> code but I'm hoping I'm overlooking something simple.

Well, one way to do this that comes to mind involves exactly one
additional simple object, converting this to a numerical sort
rather tha a string sort




data  >>>>>    FROM STRING               >>>>>      FORMULA
COM9          READ TEXT x INT ARRAY *            "COM"+sort(a)
COM1
etc.


This strips off the "COM", sorts numerically, and replaces the "COM"

This is fairly hard-coded but should be fine as long as your
application is specific enough.

regards

Stan


----------------------------------------------------------------------
Stan Bischof   Hewlett Packard Company   707-577-3994    rsb@sr.hp.com
----------------------------------------------------------------------

Outcomes