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


Groups > comp.soft-sys.math.mathematica > #6692

Re: Sorting strings

From Ulrich Arndt <ulrich.arndt@data2knowledge.de>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Sorting strings
Date 2011-11-24 12:05 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <jalbui$sj5$1@smc.vnet.net> (permalink)
References <201111231207.HAA14969@smc.vnet.net>

Show all headers | View raw


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


Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread


Thread

Re: Sorting strings Ulrich Arndt <ulrich.arndt@data2knowledge.de> - 2011-11-24 12:05 +0000

csiph-web