MathGroup Archive 2011

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

Search the Archive

Re: Sorting strings

  • To: mathgroup at smc.vnet.net
  • Subject: [mg123138] Re: Sorting strings
  • From: Ulrich Arndt <ulrich.arndt at data2knowledge.de>
  • Date: Thu, 24 Nov 2011 06:57:38 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <201111231207.HAA14969@smc.vnet.net>

I personally see benefits in equal length strings here but

Clear[getNumber]
getNumber[x_String] :=
 ToExpression[StringCases[x, y : DigitCharacter .. -> y][[1]]];

Sort[list, getNumber[#1] < getNumber[#2] &]

should do

Ulrich


Am 23.11.2011 um 13:07 schrieb Themis Matsoukas:

> 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
>

--
Ulrich Arndt
Mobile: +49 172 287 6630
ulrich.arndt at data2knowledge.de
www.data2knowledge.de

data2knowledge GmbH
Fahrenheitstr. 1
D-28359 Bremen

Gesch=E4ftsf=FChrung: Ulrich Arndt
Sitz der Gesellschaft: Bremen, Amtsgericht Bremen, HRB 26480 HB





  • Prev by Date: Forcing Certain Algebraic Forms With FullSimplify
  • Next by Date: Re: Texture on Disk in Mathematica 8?
  • Previous by thread: Re: Sorting strings
  • Next by thread: Re: Sorting strings