The RegExp object belongs to VbScript and it can be used with QTP, while handling characters of string.
The below code reverses a string , without using built in StrRev function:
string1="automation"
set obj=New RegExp 'create a RegExp object and do following setting
obj.Pattern=".{1}" 'Extract one by one character from the string using pattern property
obj.IgnoreCase=true 'ignore upper or lower case setting using ignorecase property
obj.Global=true 'The true value to global property searches for all occurrences of ' 'pattern in string
Set ch=obj.Execute(string1) 'executes the setting done above, that returns a character array
For i= ch.count-1 to 1 step -1 'Now, extract each character from that character array and
revString=revString+(ch(i)) 'print it reverse
Next
In the next post, we will discuss further on the RegExp object and its other uses...
No comments:
Post a Comment