PHP has a function called str_word_count() which allows you to count the number of words in a string, and an array or associative array of those words. Unfortunately for us, ASP doesn't support optional parameters, so we can't duplicate all of this functionality in a single function, so we'll just concentrate on the main feature of counting the number of words.
ASP
function WordCount(byVal someString)
dim position
dim spaces
spaces = 1
someString = trim(someString)
for position = 1 to len(someString)
if mid(someString, position, 1) = " " and not mid(someString, position - 1, 1) = " " then
spaces = spaces + 1
end if
next
WordCount = spaces
end function
No comments:
Post a Comment