MathGroup Archive 2009

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

Search the Archive

Re: Number of Words in a String


On Aug 11, 3:58 am, Gregory Lypny <gregory.ly... at videotron.ca> wrote:

> Is this the simplest way to find the number of words in a string?  
[...]
>         Length[ReadList[StringToStream["The cat in the hat."], Word]]

I would use StringCount:

StringCount["Now is the time for all good men to come to the aid of
their country.",
  LetterCharacter..]

will return 16. You can tweak the pattern if you want to, say, treat
strings of digits as words as well.

Cheers,
Pillsy


  • 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