MathGroup Archive 2009

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

Search the Archive

Re: Number of Words in a String

  • To: mathgroup at smc.vnet.net
  • Subject: [mg102541] Re: Number of Words in a String
  • From: Armand Tamzarian <mike.honeychurch at gmail.com>
  • Date: Wed, 12 Aug 2009 04:38:15 -0400 (EDT)
  • References: <h5r8b5$l4q$1@smc.vnet.net>

On Aug 11, 2:58 am, Gregory Lypny <gregory.ly... at videotron.ca> wrote:
> 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."], Wo=
rd]]
>
>         Returns 5.
>
> Gregory

StringCount["The cat in the hat.", Whitespace] + 1

probably a better way is use WordBoundary.

StringCount["The cat in the hat.", WordBoundary]/2

Mike


  • Prev by Date: Re: Number of Words in a String
  • Next by Date: Re: Number of Words in a String
  • Previous by thread: Re: Number of Words in a String
  • Next by thread: Re: Number of Words in a String