README.md

December 5, 2022 ยท View on GitHub

Count words in a string with 2 lines of code

Description

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

More Info

Submitted On
ByIceZer0 Software
LevelIntermediate
User Rating5.0 (10 globes from 2 users)
CompatibilityVB 6.0
CategoryString Manipulation
WorldVisual Basic
Archive File

Source 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