strText = "QTP Sreenu Blog"
strChar = "e" 'Counting the number of occurrences of e
Using Split Function
MsgBox UBound(Split(UCase(strText),UCase(strChar)))
Using Len Funtion
strChar = "e" 'Counting the number of occurrences of e
Using Split Function
MsgBox UBound(Split(UCase(strText),UCase(strChar)))
Using Len Funtion
MsgBox (Len(strText)-Len(Replace(UCase(strText),UCase(strChar),"")))
Using Len & Mid
Functions
iLen = Len(strText)
iCount=0
For i=1 To iLen
If StrComp(UCase(strChar),UCase(Mid(strText,i,1)))=0 Then
iCount = iCount+1
End If
Next
MsgBox iCount
Using Len & InStr Functions
iLen = Len(strText)
iCount=0
i=0
Do While i<iLen
iCharPosition = InStr(i+1,UCase(strText),UCase(strChar))
If iCharPosition>0 Then
iCount = iCount+1
i = iCharPosition
Else
Exit Do
End If
Loop
MsgBox iCount
Without using any built-in functions
iCount = 0
Set oRegExp = New RegExp
oRegExp.Pattern = "\d|\D|\s|\S|\t|\w|\W" 'This pattern matches with any character
oRegExp.Global = True
Set oItems = oRegExp.Execute(strText)
For i=0 To oItems.Count-1
If UCase(oItems(i)) = UCase(strChar) Then
iCount = iCount+1
End If
Next
MsgBox iCount
No comments:
Post a Comment