Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

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

Search the Archive

Re: string to a special list

  • To: mathgroup at smc.vnet.net
  • Subject: [mg57849] Re: string to a special list
  • From: János <janos.lobb at yale.edu>
  • Date: Fri, 10 Jun 2005 02:29:12 -0400 (EDT)
  • References: <200506090918.FAA28694@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

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