Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #6673 > unrolled thread

Re: Sorting strings

Started byBob Hanlon <hanlonr357@gmail.com>
First post2011-11-24 11:55 +0000
Last post2011-11-24 11:55 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.soft-sys.math.mathematica

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Sorting strings Bob Hanlon <hanlonr357@gmail.com> - 2011-11-24 11:55 +0000

#6673 — Re: Sorting strings

FromBob Hanlon <hanlonr357@gmail.com>
Date2011-11-24 11:55 +0000
SubjectRe: Sorting strings
Message-ID<jalbcc$s9c$1@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@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

[toc] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web