MathGroup Archive 2005

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

Search the Archive

Re: string to a special list


On Jun 9, 2005, at 5:18 AM, rose wrote:

>
> hi
> please how could i transform the string:
> "ab(c|d|e)fg(h|i)zx"
> into the list:
> {a,b,c|d|e,f,g,h|i,z,x}
> thanks
> rose
>
>
>

In[1]:=
str = "ab(c|d|e)fg(h|i)zx"
Out[1]=
"ab(c|d|e)fg(h|i)zx"

In[2]:=
strsplit = StringSplit[str,
    {"(", ")"}]
Out[2]=
{"ab", "c|d|e", "fg", "h|i",
   "zx"}

In[4]:=
Flatten[
   (If[StringPosition[#1,
        "|"] == {}, Characters[
       #1], #1] & ) /@
    strsplit]
Out[4]=
{"a", "b", "c|d|e", "f", "g",
   "h|i", "z", "x"}


  • Prev by Date: NMaximise Problem
  • Next by Date: Re: (suggestion to Wolfram)
  • Previous by thread: string to a special list
  • Next by thread: Re: string to a special list