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
%>
Get the best asp web hosting provider now and save 30%
Plug and play ASP membership script that integrates with PayPal to let you charge recurring membership fees.