Count characters in string
Description :
This subroutine counts the number of characters in the given string.Here I have used "wwwweeetttt" as input string.You may change as per your requirement.
Private Sub CountChar()
Dim aryCnt(123) As Integer
Dim aryChar() As String
Dim intI, intCnt As Integer
Dim strInput, strOutput As String
strInput = "wwwweeetttt"
intCnt = 65
strOutput = ""
ReDim aryChar(strInput.Length - 1)
For intI = 0 To strInput.Length - 1
aryChar(intI) = Mid$(strInput, intI + 1, 1)
Next
For intI = 0 To aryChar.Length - 1
aryCnt(Asc(aryChar(intI))) = aryCnt(Asc(aryChar(intI))) + 1
Next
For intI = 0 To aryCnt.Length - 1
If (aryCnt(intI) > 0) Then
If strOutput = "" Then
strOutput = Chr(intI) & " occurs " & aryCnt(intI) & " times"
Else
strOutput = strOutput & vbNewLine & Chr(intI) & " occurs " & aryCnt(intI) & " times"
End If
End If
Next
MessageBox.Show(strOutput)
End Sub
Please add some comment lines and description in the code.