To find a substring in a string you can use 2 approach in QTP.
Function RegExpTest(patrn, strng)
Dim regEx, Match, Matches
- Regular Expressions
- Instr - string function
Function RegExpTest(patrn, strng)
Dim regEx, Match, Matches
' Create variable.
Set regEx = New RegExp ' Create a regular expression.
regEx.Pattern = patrn ' Set pattern.
regEx.IgnoreCase = True ' Set case insensitivity.
regEx.Global = True ' Set global applicability.
Set Matches = regEx.Execute(strng) ' Execute search.
For Each Match in Matches ' Iterate Matches collection.
RetStr = RetStr & "Match found at position "
Exit For
Next
RegExpTest = RetStr
End Function
MsgBox(RegExpTest("abc", "jsdjshdabcskjdklsdj"))
Below code will find substring using instr function
If instr(1,"mainstring","main") > 0 Then
msgbox "main found in mainstring"
end if
More interview questions and answers on strings in QTP
Below code will find substring using instr function
If instr(1,"mainstring","main") > 0 Then
msgbox "main found in mainstring"
end if
More interview questions and answers on strings in QTP
- What are the different string functions in QTP?
- How to extract the digits from given string in QTP?
- How to sort the array of strings in qtp
- How to get the first character in string in QTP?
- How to convert the string into upper case in QTP?
- How to get the last character from the string in QTP?
- How to replace the string in qtp?
- How to check if substring exists in QTP?
- Explain right, mid and left functions in qtp?
- How to remove the spaces from string in qtp?
- What are the trim functions in qtp?
- Explain replace function in qtp with example.
- Explain the split function in qtp with example.
- Explain lcase and ucase functions in qtp.
- What is the len function in qtp?
- Give the example of instr function in qtp
No comments:
Post a Comment
Please Leave your reply. We value your feedback and inputs