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

can any one please tell me QTP 9.2 supports which version of IE and Mozilla firefox.

1 Answers  


what is the hierarchy to use properties in descriptive programming

0 Answers  


On what document base Descriptive programming is written if build is not yet ready ?

0 Answers  


What processes will be required to manage updates to the web site's content, and what are the requirements for maintaining, tracking, and controlling page content, graphics, links, etc.?

0 Answers  


Explain the features and benefits of quick test pro(qtp)?

0 Answers  


Explain Descriptive Programming Types with Examples?

0 Answers  


how to add a runtime parameter to a data sheet?

6 Answers  


Inserting a Call to Action is not importing all columns in Datatable of globalsheet. Why?

1 Answers   Crea,


How to Practice QTP Scripts?

1 Answers  


What are objects? how do you select the unknow object?

3 Answers  


Where should we turn Smart Identification ON in QTP?

5 Answers  


in process of project exaplnation the defects are says frequently r not?

1 Answers  


Categories