Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #6701
| From | Ray Koopman <koopman@sfu.ca> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: Sorting strings |
| Date | 2011-11-24 12:10 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <jalc75$sm8$1@smc.vnet.net> (permalink) |
| References | <jainvm$eop$1@smc.vnet.net> |
On Nov 23, 4:12 am, Themis Matsoukas <tmatsou...@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
Drop the "a", convert to numeric, sort, convert to ascii,
and re-attach the "a".
In[1]:=
"a"<>ToString@#&/@Sort[ToExpression@StringDrop[#,1]&/@
{"a1", "a2", "a20", "a12"}] //InputForm
Out[1]//InputForm=
{"a1", "a2", "a12", "a20"}
Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Find similar | Unroll thread
Sorting strings Themis Matsoukas <tmatsoukas@me.com> - 2011-11-23 12:12 +0000 Re: Sorting strings Costa Bravo <q13a27tt@aol.com> - 2011-11-24 12:07 +0000 Re: Sorting strings "Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com> - 2011-11-24 12:07 +0000 Re: Sorting strings Ray Koopman <koopman@sfu.ca> - 2011-11-24 12:10 +0000
csiph-web