Codefixer - ASP tutorials, resources and software
asp.netPRO “Best ASP.NET Host” – DiscountASP.NET
Home   Articles   Resources   ASP directory   ASP Tutorials   Code Snippets   ASP Applications   Forum
Monday 12 May
MembersPro PayPal - ASP Membership software

ASP.NET 3.5 Hosting – DiscountASP.NET


ASP Partner ASP Partner ASP Partner more partners...

Count Number of Words in a Sentence with ASP

Below is a very simple function that will return the number of words in a sentence. The function also calls the VBScript Split and UBound functions.

<%
Function WordCount(sInput)
'Declare variables
Dim myWordArray, iWords

'The Split function will split the string sInput into an array and retrieve the number
'of elements in it using the space character as the delimiter
myWordArray = Split(sInput ," ")
'store the amount of words in iWords, remember that the Split function returns
'an array that is zero based so add 1
iWords = Ubound(myWordArray) +1
'Return the amount of words
WordCount=iWords
End Function

'Declare variables
Dim sText, iWordCount

sText = "I really like Codefixer's Polling Software."
'Count the number of words in our string sText
'using WordCount Function and assign value to variable iWordCount

iWordCount=WordCount(sText)
'Write out number of words in our string
Response.Write "There are " & iWordCount & " words in " & sText
%>





If you have any code snippets to share with full credit given then send an email to Codesnippets - You'll receive full credit and a link back to your site.

ASP.NET 3.5/2.0 Web Hosting: 3 Months FREE – Click Here!




About | Contact | Advertise | Feedback | Hire Us | Link

Site developed by Michael Wall - Web Design Belfast N.Ireland.
Copyright © 2000-2008. All rights reserved.

Do you intend to move to ASP.NET or have you already?
Yes will do
Have done
ASP does fine
Not a priority


Directory Software