*To*: mathgroup@smc.vnet.net*Subject*: [mg10930] Re: String patterns*From*: Paul Abbott <paul@physics.uwa.edu.au>*Date*: Thu, 12 Feb 1998 20:16:13 -0500*Organization*: University of Western Australia*References*: <6brf6t$e78@smc.vnet.net>

MJE wrote: > How good is Mathematica at this kind of string manipultion and > searching? Here is a basic implementation: In[1]:= string="I love Mathematica"; In[2]:= chars=Characters[string] In[3]:= ToUpperCase[chars] Select all upper case letters (and " ",".","-",":"): In[4]:= Select[%,UpperCaseQ[#]|| MemberQ[ToCharacterCode/@{" ",".","-",":"},ToCharacterCode[#]]&] Form the trigraphs explicitly In[5]:= trigraphs=Apply[StringJoin,Partition[%,3,1],{1}] and compute the frequencies: In[6]:=<<Statistics`DataManipulation` In[6]:= Reverse/@(Frequencies[trigraphs]//Sort//Reverse)//TableForm Out[6]//TableForm= MAT 2 VE 1 TIC 1 THE 1 OVE 1 MA 1 ... There is probably a neat pattern-matching way of computing the frequencies without constructing the trigraphs explicitly. Cheers, Paul ____________________________________________________________________ Paul Abbott Phone: +61-8-9380-2734 Department of Physics Fax: +61-8-9380-1014 The University of Western Australia Nedlands WA 6907 mailto:paul@physics.uwa.edu.au AUSTRALIA http://www.pd.uwa.edu.au/~paul God IS a weakly left-handed dice player ____________________________________________________________________