Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to split up a string, and then count each character?

Status
Not open for further replies.

havoc33

Technical User
Dec 3, 2003
16
NO
I'm really stuck on this.. how do I split up a string and then count each character? For example that the letter A had 3 occurences, b had 2 etc. etc.. I've been working on this for several days, but I can't figure it out. So any help would be appreciated.
 

Code:
Sub CountChars(myString As String)
Dim Counts(255) As Integer
Dim n           As Integer

For n = 1 To Len(myString)
    Counts(Asc(Mid$(myString, n, 1))) = Counts(Asc(Mid$(myString, n, 1))) + 1
Next n

For n = 0 To 255
   If Counts(n) > 0 Then
      Debug.Print Chr$(n), Counts(n)
   End If
Next n

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top