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

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain the differences between table and db checkpoints?

764


Pls can anybody send me the Recent Technical and Interview Questions Which were asked in IBM(QTP)Automation PLZZZZZZZZZ

1788


How reliable are the site's Internet connections required to be? And how does that affect backup system or redundant connection requirements and testing?

928


Please guide me release notes of Automation once scripts are completed

1655


What are private functions in QTP? How they can be called from the function library?

815


How qtp recognizes the object?

869


What are the differences between quicktest professional and winrunner?

770


Explain how qtp identifies object?

832


Can any one tell me how to write a script for selecting open option in File menu of A word document.here you have to add objects to OR.try like that and give me the ans.i asked this question to so many but no one knows.if any one know the answer plz let me know

1640


How you can make an action as re-usable action?

876


What is test object?

892


How to give a call to another action from one action?

860


How to test fly out menu in qtp?

714


wht type of User defined functions or Java Releated functions do we write in VB scripting

2024


What are the benefits of quick test pro(qtp)?

765