VBScript to find the number of times a particular character is repeated in a given string. without using len, mid, right, left

2,640 views
Skip to first unread message

Malluri Ramesh

unread,
Aug 25, 2014, 4:26:47 AM8/25/14
to mercu...@googlegroups.com
VBScript to find the number of times a particular character is repeated in a given string.  without using len, mid, right, left

bhavin v patel

unread,
Aug 25, 2014, 4:45:35 PM8/25/14
to mercu...@googlegroups.com
Good one..
You can do with regrular expression..

Gautham Maroli

unread,
Aug 25, 2014, 8:03:33 PM8/25/14
to mercu...@googlegroups.com
str_1= "THis is a test"
count = 0
str_1 = LCase(str_1) & "@"

str_len = InStr(str_1,"@")
'MsgBox str_len

For i = 1To str_len
    IfInStr(i, str_1, "t") > 0Then
        str_pos = InStr(i, str_1, "t")
        count = count +1
        i = str_pos
    EndIf
Next

MsgBox"String Count:"&count
>"COUNT:"


Regards,
Gautham Maroli


On Mon, Aug 25, 2014 at 6:26 PM, Malluri Ramesh <malluri...@gmail.com> wrote:
VBScript to find the number of times a particular character is repeated in a given string.  without using len, mid, right, left

--
--
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

---
You received this message because you are subscribed to the Google Groups "QTP - HP Quick Test Professional - Automated Software Testing" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mercuryqtp+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Gautham Maroli

unread,
Aug 26, 2014, 4:01:43 AM8/26/14
to mercu...@googlegroups.com
With Regular Expression:

count = 0
str_1= "This is a Test"

Set regExp_1 = NewRegExp
regExp_1.IgnoreCase = True
regExp_1.Global = True
regExp_1.Pattern = "t"

Set str_match = regExp_1.Execute(str_1)
ForEach Matchin str_match
  count = count +1

Next
MsgBox"String Count:"&count

Regards,
Gautham Maroli



--

ranjan kumar

unread,
Aug 28, 2014, 1:43:05 PM8/28/14
to mercu...@googlegroups.com
This ll give number of times a character or word is repeating
s="hello how r u h"
Msgbox ubound(split(s,"h"))

Regards
Ranjan

QTP Rss

unread,
Sep 2, 2014, 8:00:22 AM9/2/14
to mercu...@googlegroups.com

Dear All,

 

To summaries all, we can find a conclusion that both Regular Expression(by Gutam) and Split(by Ranja) will work but depending on the cases.

1.      If the search string(word) is unique then use Split.

Pro: If we want to find a word called ‘test’ out of the string ‘This is a test for tester’. Then count will be 2, but actual result should be 1.

Otherwise always advice to use regular expression.

Regard,
Kapi Das
Reply all
Reply to author
Forward
0 new messages