Re: Simple String question

*To*: mathgroup at smc.vnet.net*Subject*: [mg110691] Re: Simple String question*From*: Sunt <sunting.05 at gmail.com>*Date*: Fri, 2 Jul 2010 07:25:57 -0400 (EDT)*References*: <i0k2ft$jra$1@smc.vnet.net>

On Jul 2, 2:54 pm, "S. B. Gray" <stev... at ROADRUNNER.COM> wrote: > I have strings like foo="623 715". foo will always be 3 digits, space, 3 > digits. I need to put each set of digits in numerical order and then put > the two triples in order. This would give 157 236. There must be a > simple way to do this, but I see nothing under string sorting. > > Steve Gray Hi, The following method works, but looks not so simple~~ foo = "623 715"; hf[s_String] := Module[ {sl = StringSplit[s]}, StringJoin@ Insert[StringJoin /@ ((Map[ ToString, #, {2}] &)@(Sort /@ (ToExpression /@ (Characters / @ sl)))), " ", 2]] hf[foo]