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

What is Descriptive Programing? In which cases, we will go for descriptive programing?

2 Answers   CTS,


Does Low-level recording capture mouse movements?

0 Answers  


How to switch between browser tabs? )moving from one tab to another tab)

1 Answers   CTS,


what is the silent mode in WR?

1 Answers  


what is mean by soi in object identification

1 Answers  






How can you identify the browser and its information using the qtp script?

0 Answers  


Is the qtp course will help to create a virtual object?

0 Answers  


how can you describe the basic flow of automation with conditional and programmatic logic?

1 Answers   Ordain Solutions,


Explain the views in the QTP GUI?

0 Answers  


what is the extension for the test version of the script?

5 Answers   TCS,


In web page there is five OK buttons available, while recording i click on 3rd OK button, How QTP identify the 3rd OK button while running script? Is qtp identify 3rd ok button?

14 Answers   Polaris,


How do we retrieve the content from a text box in a web page

2 Answers  


Categories