VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Character counter

by Chris Wilson (9 Submissions)
Category: String Manipulation
Compatability: Visual Basic 3.0
Difficulty: Advanced
Date Added: Wed 3rd February 2021
Rating: (4 Votes)

A FAST and EASY way to count the number of occurrences of one string within another! Please vote for this tip if you find it useful.

Rate Character counter

Private Sub Test()
Const mystr = "This is a test of the split function"
' returns 6
Debug.Print Occurs(mystr, "t")
End Sub
Public Function Occurs(ByVal strtochk As String, ByVal searchstr As String) As Long
' remember SPLIT returns a zero-based array
Occurs = UBound(Split(strtochk, searchstr)) + 1
End Function

Download this snippet    Add to My Saved Code

Character counter Comments

No comments have been posted about Character counter. Why not be the first to post a comment about Character counter.

Post your comment

Subject:
Message:
0/1000 characters