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
Original Author: IceZer0 Software
Code
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
Loading Comments ...
Comments
No comments have been added for this post.
You must be logged in to make a comment.