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 %>
Recent Comments