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


Comments

Author: Abhay Kumar Raut05 Nov 2009 Member Level: Gold   Points : 0

Please add some comment lines and description in the code.



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: