Is there a function to find the number of occurrences of sub
strings within a string?



Is there a function to find the number of occurrences of sub strings within a string?..

Answer / nath t

The below function returns number of occurrences of sub
string within a string

Function SubStrOccur(Str, SubStr)
Occr = split(Str, SubStr)
SubStrOccur = ubound(Occr)
End Function

Scenario 1:

Str = "SairamSairam Sairam"
SubStr = "Sai"
msgbox "Given SubString("&SubStr&") appeared "&SubStrOccur
(Str, SubStr)&" time(s) in given String("&Str&")"

Function return 3 (bcz "Sai" appears 3 times in the given
string.)



Scenario 2:

Str = "SairamSairam Sairam"
SubStr = "sai"
msgbox "Given SubString("&SubStr&") appeared "&SubStrOccur
(Str, SubStr)&" time(s) in given String("&Str&")"

Function return 0 (bcz here "sai" is in small letters
doesn't appear in the given string.)

Is This Answer Correct ?    3 Yes 0 No

Post New Answer

More QTP Interview Questions

suppose take one row in a row 16 columns is there.in 16 columns 16 numbers is there.but i want to get each 3 column number.o/p :5 columns get in 16 columns means. so can anybody write this function? plz send if u know the answer.

2 Answers   Bosch,


How to use descriptive programming?

0 Answers  


Hi Friends... What you are doing in Regression Testing and how many test cases you ran in regression testing... suppose there is 1000 test cases is there how many test cases again you run .. 1000 test caes r how many... thanx in advance..

6 Answers  


WAT IS DATA BASE AND XML CHECK POINT ?HOW TO IMPLEMENT IT ... GIVE PROPER EXAMPLE FOR IT

0 Answers   Infosys,


How to send QTP test results to an email...(with out using Quality Center)?

11 Answers  






if Object repository contain x and y properties. we do not know whether they are mandatory or assistive properties. While executing the script qtp will use both the properties or only sufficient properties to identify the object. It means it use OR (or) AND

8 Answers   ADP,


Tell me few important difference Between QTP and WinRunner?

9 Answers   TCS,


what is the use of VIRTUAL OBJECTS? explain ?

4 Answers  


What is the registration process and examination fees?

0 Answers  


What is the synchronization point in qtp?

0 Answers  


Explain types of output values?

0 Answers  


Given a string variable contain a full name (last name, first name), using vbscripting, how can you extract first and last name and save them into two different variables.

2 Answers   Banking,


Categories