MathGroup Archive 2001

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

Search the Archive

Re: Working with strings

  • To: mathgroup at smc.vnet.net
  • Subject: [mg31962] Re: [mg31940] Working with strings
  • From: Omega Consulting <omega_consulting at yahoo.com>
  • Date: Fri, 14 Dec 2001 04:21:28 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

At 12:08 AM 12/13/2001, Brian Higgins wrote:
>I have a list of string characters that I would like to group in a
>particular way. The list has the following structure:
>
>{n UpperCase Characters, x, m UpperCase Characters}
>
>Here is an example:
>
>myString={"S", "T", "M", "x", "R", "K", "P", "G"}
>
>Now I would like to form the following groupings:
>
>{"SxR", "SxK", "SxP", "SxG", "TxR", "TxK", "TxP", "TxG", "MxR", "MxK",
>"MxP", \
>"MxG"}
>
>A brute force way of doing this is
>
>subString[n_] := Split[myString, UpperCaseQ[#2] && UpperCaseQ[#1]
>&][[n]];
>
>Flatten[Outer[StringJoin, Outer[StringJoin, subString[1],
>subString[2]],
>     subString[3]]]
>
>Does anyone have any elegant way of doing this with perhaps using
>replacement rules?
>
>Thanks much,
>
>
>Brian

I don't know about elegant, but here's another way to do it.

{x,y}=myString/.{a___,"x",b___}->{{a},{b}};

Flatten[Outer[(#1<>"x"<>#2)&,x,y]]

--------------------------------------------------------------
Omega Consulting
"The final answer to your Mathematica needs"

Spend less time searching and more time finding.
http://www.wz.com/internet/Mathematica.html



  • Prev by Date: RE: Simple Eval Question
  • Next by Date: RE: Preserve subscripts like integers using N
  • Previous by thread: Re: Working with strings
  • Next by thread: RE: Working with strings