Advertisement
4_2005-2006 String Manipulation #166376

Count words in a string with 2 lines of code

Have you been using the instr function, or 3rd party functions to find the word count of a block of text. Now you find it in ONLY 2 LINES OF CODE - NO API CALLS - NO MODULES / CLASSES / CONTROLS - PURE VB CODE

AI

AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Source Code
original-source
Public Function WordCount(Text as String) as Long
'Declare an Array
Dim splitText() as String
splitText = Split(Text, " ") 
'Split it using a space charachter for where to split it.
WordCount = Ubound(splitText) + 1 
'Set the function return to the end of the array. Ex: See Spot Run! would make splitText(0) = See, splitText(1) = spot, and splitText(2) = Run! - 2 is the highest so 1 is added to it to make the word count
'Good luck on your vb programming - IceZero
End Function
Original Comments (3)
Recovered from Wayback Machine