Services & Resources / Wolfram Forums / MathGroup Archive
-----

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: [mg102521] Re: Number of Words in a String
  • From: Pillsy <pillsbury at gmail.com>
  • Date: Wed, 12 Aug 2009 04:34:34 -0400 (EDT)
  • References: <h5r8b5$l4q$1@smc.vnet.net>

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