RE: Nesting / Repetitive Functions
- To: mathgroup at smc.vnet.net
- Subject: [mg36085] RE: [mg36073] Nesting / Repetitive Functions
- From: "DrBob" <majort at cox-internet.com>
- Date: Wed, 21 Aug 2002 05:51:49 -0400 (EDT)
- Reply-to: <drbob at bigfoot.com>
- Sender: owner-wri-mathgroup at wolfram.com
Here's another method that seems more efficient: X = "Cat Basic Algebra None TM Expand TM Factor"; U = # - Range[0, Length@# - 1] &@StringPosition[X, " "] f = StringDrop[#1, #2] & FoldList[f, X, U] // TableForm Bobby Treat -----Original Message----- From: DrBob [mailto:majort at cox-internet.com] To: mathgroup at smc.vnet.net Subject: [mg36085] RE: [mg36073] Nesting / Repetitive Functions Try this. (Note that U isn't used.) X = "Cat Basic Algebra None TM Expand TM Factor"; U = StringPosition[X, " "][[All, 1]] f = StringDrop[#, StringPosition[#, " "][[1]]] & NestList[f, X, Length@StringPosition[X, " "]] // TableForm {4, 10, 18, 23, 24, 25, 26, 27, 28, 29, 32, 39, 42} StringDrop[#1, StringPosition[#1, " "]ã??1ã??] & "Cat Basic Algebra None TM Expand TM Factor" "CatBasic Algebra None TM Expand TM Factor" "CatBasicAlgebra None TM Expand TM Factor" "CatBasicAlgebraNone TM Expand TM Factor" "CatBasicAlgebraNone TM Expand TM Factor" "CatBasicAlgebraNone TM Expand TM Factor" "CatBasicAlgebraNone TM Expand TM Factor" "CatBasicAlgebraNone TM Expand TM Factor" "CatBasicAlgebraNone TM Expand TM Factor" "CatBasicAlgebraNone TM Expand TM Factor" "CatBasicAlgebraNoneTM Expand TM Factor" "CatBasicAlgebraNoneTMExpand TM Factor" "CatBasicAlgebraNoneTMExpandTM Factor" "CatBasicAlgebraNoneTMExpandTMFactor" Bobby Treat -----Original Message----- From: Ashraf El Ansary [mailto:Elansary at btopenworld.com] To: mathgroup at smc.vnet.net Subject: [mg36085] [mg36073] Nesting / Repetitive Functions Dear All, I was wondering if there was any method besides the Nest[] function to repeat function more than once during the same Input/Output cycle .. Actually what I'm trying to reach is as follows: Defining X= ToString[HoldForm[Cat"Basic Algebra" None TM"Expand" TM"Factor" ]]; Defining U=Part[Flatten[StringPosition[X," "]],Range[1,Length[Flatten[StringPosition[X," "]]],2]] That's giving the location of Blank spaces within X. Then One=StringDrop[X,{U[[1]],U[[1]]}]; Two[i_]:=StringDrop[%,{U[[i+1]]-i,U[[i+1]]-i}]; I'm Trying to apply In[32]:= One Out[32]= CatBasic Algebra None TM Expand TM Factor In[33]:= Two[1] Out[33]= CatBasicAlgebra None TM Expand TM Factor In[34]:= Two[2] Out[34]= CatBasicAlgebraNone TM Expand TM Factor In[35]:= Two[3] Out[35]= CatBasicAlgebraNoneTM Expand TM Factor In[36]:= Two[4] Out[36]= CatBasicAlgebraNoneTMExpand TM Factor ------------------ It is not just that I'd like to remove the blanks but rather interested in the idea.. I tried to build a loop but % didn't work since % doesn't work unless the result of the whole loop is out, I know I can use Nest[] but don't know how to do it... Any suggestions.... Thanks. I know I might have a silly answer.. I just had Mathematica for less than a couple of weeks... Thanks You ALL