Re: Pure Function for String Selection
- To: mathgroup at smc.vnet.net
- Subject: [mg60974] Re: Pure Function for String Selection
- From: "dkr" <dkrjeg at adelphia.net>
- Date: Wed, 5 Oct 2005 02:28:34 -0400 (EDT)
- References: <dht479$hl1$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Edson, In[8]:= maxseq[s_String,ch_String]:=Max[StringLength/@StringCases[s,ch..]]; (maxseq yields the maximum number of repetitions of the character ch in the string s, provided ch appears at least once. If ch does not appear in s, then maxseq yields -Infinity.) In[9]:= maxseq["122XXXXXX222XX","X"] Out[9]=6 In[10]:= filter[origList:{__String}]:= Select[origList,(maxseq[#,"1"]<8&&maxseq[#,"X"]<6&&maxseq[#,"2"]<6)&]; In[13]:= eg1={"11112X122X1XXX","122XXXXXX222XX","11111111222112"}; filter[eg1] Out[14]= {11112X122X1XXX} In[15]:= eg2={"22222XXX22XXXXX","XXXXXXXXX222XX","22111112222112"}; filter[eg2] Out[16]= {22222XXX22XXXXX,22111112222112} In the second example, the first string selected has no "1"'s (i.e., there are no repetitions of "1"'s, and consequently the number of repetitions of "1"'s is certainly less than 8).