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 positiondim spacesspaces = 1someString = trim(someString)for position = 1 to len(someString)if mid(someString, position, 1) = " " and not mid(someString, position - 1, 1) = " " thenspaces = spaces + 1end ifnextWordCount = spacesend function
No comments:
Post a Comment