Re: Working with strings
- To: mathgroup at smc.vnet.net
- Subject: [mg31952] Re: [mg31940] Working with strings
- From: Ken Levasseur <Kenneth_Levasseur at uml.edu>
- Date: Fri, 14 Dec 2001 04:21:13 -0500 (EST)
- References: <200112130608.BAA01001@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Brian: Here's a a way to do it with patterns and Outer: In[30]:= Outer[(#1 <> "x" <> #2) &, myString /. {{p___, "x", s___} -> Sequence[{p}, {s}]}] // Flatten {"SxR", "SxK", "SxP", "SxG", "TxR", "TxK", "TxP", "TxG", "MxR", "MxK", "MxP", "MxG"} Ken Levasseur Math. Sci. UMass Lowell 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
- References:
- Working with strings
- From: bghiggins@ucdavis.edu (Brian Higgins)
- Working with strings