Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to count number of word in text

How to count number of word in text

Scheduled Pinned Locked Moved C#
tutorial
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    eyalso
    wrote on last edited by
    #1

    Hi I need a code example or an known Object that can count the number of word in a text eyalso

    R 1 Reply Last reply
    0
    • E eyalso

      Hi I need a code example or an known Object that can count the number of word in a text eyalso

      R Offline
      R Offline
      Robin Panther
      wrote on last edited by
      #2

      Why don't you try using string.Split(" \t\n.;:\"\'") with cleaning empty results? may be some more symbols, but you got the idea. You can use Regex for same effect... ____________________________________________ Robin Panther http://www.robinland.com

      E 1 Reply Last reply
      0
      • R Robin Panther

        Why don't you try using string.Split(" \t\n.;:\"\'") with cleaning empty results? may be some more symbols, but you got the idea. You can use Regex for same effect... ____________________________________________ Robin Panther http://www.robinland.com

        E Offline
        E Offline
        eyalso
        wrote on last edited by
        #3

        can u send me code example (with regex or split) thanks eyalso

        G 1 Reply Last reply
        0
        • E eyalso

          can u send me code example (with regex or split) thanks eyalso

          G Offline
          G Offline
          Graham Nimbley
          wrote on last edited by
          #4

          string input="Hello World!"+Environment.NewLine+"Goodbye World.";

          int wordCount=Regex.Matches(input,"[\\w\'-]+").Count;

          Console.WriteLine("Word Count: {0}",wordCount);

          Needs further testing, and probably not perfect. But on the tests I have done so far, it seems to account for itself. Hope this helps, Graham. -- modified at 17:50 Sunday 30th April, 2006

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups