Visual Basic 6 function "CountChars"

Go back

Below you'll find the source for the Visual Basic 6 function CountChars.

Attribute VB_Name = "modCountChars"
' This function is downloaded from:
' You may freely distribute this file but please leave all comments, including this one, in it.
' @Author Stefan Thoolen <>

Option Explicit

' Counts how many a character occures in a string
' @param    String  txt     The text to search in
' @param    String  search  The text to count
' @return   Integer         The amount of search in txt
' @author   Stefan Thoolen <>
Public Function CountChars(ByVal txt As String, ByVal search As String) As Integer
    Dim arr() As String
    arr = Split(txt, search)
    CountChars = UBound(arr) - LBound(arr)
End Function