Count Number of Words in a Sentence using ASP
October 16, 2009
There is no function in ASP to count number of words in sentence or long string. Bellow is very simple function that count number of words and return that count.
< % Function CountWords (StrValue) Dim iWords, mLengthWithSpaces, mLengthWithoutSpaces ' following line calculate the actual length of string mLengthWithSpaces = Len(StrValue) ' following line remove all spaces from string and then calculate the length of string mLengthWithoutSpaces = Len(Replace(StrValue, " ", "")) ' subtract length (without spaces) from actual string length iWords = mLengthWithSpaces - mLengthWithoutSpaces CountWords = iWords + 1 End Function 'example Msg = "This is text string" Response.Write CountWords(Msg) 'output will be 4 %>
Related Posts
Tags: ASP
Posted in 
(3 votes, average: 4.67 out of 5)
content rss
Recent Comments