Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2010

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

Search the Archive

Re: Simple String question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg110730] Re: Simple String question
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Sat, 3 Jul 2010 08:20:19 -0400 (EDT)

mySort[str_String] := StringJoin @@
  Insert[
   Flatten[
    Sort[
     Sort /@ Characters /@ StringSplit[str]]],
   " ", 4]

data = Table[ToString[
    RandomInteger[{100, 999}]] <> " " <>
   
   ToString[RandomInteger[{100, 999}]],
  {5}]

{299 945,918 889,275 396,938 962,947 461}

mySort /@ data

{299 459,189 889,257 369,269 389,146 479}


Bob Hanlon

---- "S. B. Gray" <stevebg 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




  • Prev by Date: Neat demonstration: "Celestial Map of... Stars.."
  • Next by Date: Re: plot
  • Previous by thread: Re: Simple String question
  • Next by thread: Re: Simple String question