Re: Number of Words in a String
- To: mathgroup at smc.vnet.net
- Subject: [mg102526] Re: [mg102483] Number of Words in a String
- From: Tomas Garza <tgarza10 at msn.com>
- Date: Wed, 12 Aug 2009 04:35:30 -0400 (EDT)
- References: <200908110802.EAA21929@smc.vnet.net>
I would use In[1]:= yourlist="The cat in the hat." In[2]:= Length[StringSplit[yourlist]] Out[2]= 5 I feel it is simple enough. Tomas > Date: Tue, 11 Aug 2009 04:02:50 -0400 > From: gregory.lypny at videotron.ca > Subject: [mg102483] Number of Words in a String > To: mathgroup at smc.vnet.net > > Hello everyone, > > Is this the simplest way to find the number of words in a string? > Seems a little complicated, and I can't seem to turn it into a > function because when I replace the string with the argument > placeholder myString_ I get an error message saying that a string is > expected in that spot. > > Length[ReadList[StringToStream["The cat in the hat."], Word]] > > Returns 5. > > Gregory >
- References:
- Number of Words in a String
- From: Gregory Lypny <gregory.lypny@videotron.ca>
- Number of Words in a String