Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Sorting strings

  • To: mathgroup at smc.vnet.net
  • Subject: [mg123119] Re: Sorting strings
  • From: Bob Hanlon <hanlonr357 at gmail.com>
  • Date: Thu, 24 Nov 2011 06:54:11 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <201111231207.HAA14969@smc.vnet.net>

data = {"a1", "a2", "a20", "a12"};

SortBy[data, ToExpression[StringDrop[#, 1]] &]

{"a1", "a2", "a12", "a20"}


Bob Hanlon


On Wed, Nov 23, 2011 at 7:07 AM, Themis Matsoukas <tmatsoukas at me.com> wrote:
> Sorting this list of strings
>
> {"a1", "a2", "a20", "a12"} // Sort
>
> I get
>
> {"a1", "a12", "a2", "a20"}
>
> but I would like the numerals to be sorted as numbers, i.e., as
>
> {"a1", "a2", "a12",  "a20"}
>
> Is this possible or do I have to rename "a1" into "a01" etc?
>
> Thanks
>
> Themis



  • Prev by Date: Re: How to integrate a function over a polygon
  • Next by Date: Re: Sorting strings
  • Previous by thread: Sorting strings
  • Next by thread: Re: Sorting strings