How to Get a Count of letters in QTP using VB Script

3,647 views
Skip to first unread message

bnbab

unread,
Mar 10, 2011, 7:41:53 AM3/10/11
to QTP - HP Quick Test Professional - Automated Software Testing
Hi
I am new to this group

I have a question for VB Scripting in QTP
like

i have a name : "adarshavivahasatram"
I want to get a count of "a " howmany a's are there in the above
name .pls provide me howmany wayswe can get the count of a and let me
know the code

govind sirvi

unread,
Mar 10, 2011, 8:46:27 AM3/10/11
to mercu...@googlegroups.com, bnbab
Hi,
find the below code
str="adarshavivahasatram"
l=len(str)
For i=1 to l
ch=mid(str,i,1)
If ch="a" Then
    cntr=cntr+1
End If
Next
msgbox "The Number of a's present in " &str & " is "&cntr





--
You received this message because you are subscribed to the Google
"QTP - HP Quick Test Professional - Automated Software Testing"
group.
To post to this group, send email to Mercu...@googlegroups.com
To unsubscribe from this group, send email to
MercuryQTP+...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/MercuryQTP?hl=en



--
Thanks and Regards,
Govind

Karthikeyan

unread,
Mar 10, 2011, 8:56:53 AM3/10/11
to mercu...@googlegroups.com
Hi,

You could use InStr string function to count number of sub-strings within a string.

Do read about "InStr", you should be able to do the code.

Regards,
Karthik

nani babuborra

unread,
Mar 10, 2011, 12:23:10 PM3/10/11
to mercu...@googlegroups.com
great thanks

$rinivas K

unread,
Mar 11, 2011, 4:19:36 AM3/11/11
to mercu...@googlegroups.com
Dim Str, Schar
Str = inputbox("Enter String: ")

Schar = inputbox("Enter search char.: ")

cnt = len(str)
for i=1 to cnt
char = mid(Str, i, 1)

if ucase(char) = ucase(Schar) then
counter = counter+1
end if
next

msgbox "No of " & Schar & " character in the string " & Str &": " & counter

On Thu, Mar 10, 2011 at 6:11 PM, bnbab <babubor...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages