Custom Search

Sunday, January 2, 2011

Get the repeated character in one string

Function GetCharCount(strChar,strSearchIn)
    dim intCounter
    for intCounter = 1 to len(strSearchIn)
         if Mid(strSearchIn,intCounter,1)=strChar then
             GetCharCount=GetCharCount+1
         end if
    next
End Function
msgbox GetCharCount("s", "this is a string")

======Second method=========
str="this is a string"
msgbox Len(str)-Len(Replace(str,"s",""))


No comments:

Post a Comment

Note: Only a member of this blog may post a comment.