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


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

Re: Sorting strings

Started byUlrich Arndt <ulrich.arndt@data2knowledge.de>
First post2011-11-24 12:05 +0000
Last post2011-11-24 12:05 +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 Ulrich Arndt <ulrich.arndt@data2knowledge.de> - 2011-11-24 12:05 +0000

#6692 — Re: Sorting strings

FromUlrich Arndt <ulrich.arndt@data2knowledge.de>
Date2011-11-24 12:05 +0000
SubjectRe: Sorting strings
Message-ID<jalbui$sj5$1@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@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


[toc] | [standalone]


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


csiph-web