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
Rate Count words in a string with 2 lines of code
(3(3 Vote))
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
Count words in a string with 2 lines of code Comments
No comments yet — be the first to post one!
Post a Comment