Counting specific chars in a string
It looks like there is no function for counting the amount of a certain character(s) in a string (or I am just dumb). Right now I've got this:
Code:
Public Function StrCount(String1, String2) As Long
For x = 1 To Len(String1)
If Mid(String1, x, Len(String2)) = String2 Then StrCount = StrCount + 1
Next x
End Function
But this seems to work too:
Code:
Public Function StrCount(String1, String2) As Long
Dim sCount() As String
sCount = Split(String1, String2)
StrCount = UBound(sCount)
End Function
But surely there is a VB function that I missed, or an API. There's a few string API functions, but none of them seem to do anything related to this...
Any Ideas?:confused: :confused: :confused: