Posted By

Scooter on 10/11/08


Tagged

strings


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

nelda751
benrudolph


WordCount


 / Published in: ASP
 

URL: http://reusablecode.blogspot.com/2008/10/wordcount.html

  1. <%
  2. ' Copyright (c) 2008, reusablecode.blogspot.com; some rights reserved.
  3. '
  4. ' This work is licensed under the Creative Commons Attribution License. To view
  5. ' a copy of this license, visit http://creativecommons.org/licenses/by/3.0/ or
  6. ' send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California
  7. ' 94305, USA.
  8.  
  9. ' Count the number of words in a string.
  10. function WordCount(byVal someString)
  11. dim position
  12. dim spaces
  13.  
  14. spaces = 1
  15. someString = trim(someString)
  16.  
  17. for position = 1 to len(someString)
  18. if mid(someString, position, 1) = " " and not mid(someString, position - 1, 1) = " " then
  19. spaces = spaces + 1
  20. end if
  21. next
  22.  
  23. WordCount = spaces
  24. end function
  25. %>

Report this snippet  

You need to login to post a comment.