C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » String Manipulations »

Count characters in string


Posted Date: 04 Nov 2009    Resource Type: Code Snippets    Category: String Manipulations
Author: ProgrammerMember Level: Diamond    
Rating: 1 out of 5Points: 5



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



Responses

Author: Abhay    05 Nov 2009Member Level: Diamond   Points : 0
Please add some comment lines and description in the code.


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
String  .  Count characters in string  .  Count  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Function to Sort comma(,) separated string
Previous Resource: Compare strings
Return to Discussion Resource Index
Post New Resource
Category: String Manipulations


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use