Copying random length part of the string. - Printable Version +- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums) +-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP) +--- Forum: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming) +--- Thread: Copying random length part of the string. (/Thread-Copying-random-length-part-of-the-string) |
Copying random length part of the string. - unbeliever - 12-29-2009 Dear All, I have following outertext for WebElement: "Change page: < 1 2 3 4 5 6 7 8 9 10 ... > | Displaying page 1 of 426, items 1 to 10 of 4257." What I need to do is to grab 4257 out of this string and assign it to a variable. The trickiest part is that number 4257 can be different: it can consist of different amount of digits, for example this value can be 25, 2454 or 10983. So I cannot just assume that it is four digits. I have a solution in mind: - pick part of the string "items 1 to 10 of " - calculate amount of subsequent digits after it - grab sequence of these digits (value) and assign it to the variable. Can you please advise me how to code it with examples? Thanks in advance! RE: Copying random length part of the string. - cashgiga - 12-29-2009 This can be very easily you can handle: 1.Get the text using GetROProeprty method (Ex. webElement.getroproperty("innertext")) and assign it to a variable. 2.Then split the value of variable using Split function (ex. value = Split(text, ,-1) 3.Then exactvalue = CInt(Ubound(value)) You will get final part of the digit. RE: Copying random length part of the string. - Saket - 12-29-2009 alternately, you can take trim your value upto the first space(" ") in string Code: str = "Change page: < 1 2 3 4 5 6 7 8 9 10 ... > | Displaying page 1 of 426, items 1 to 10 of 4257." correction - you can take trim your value upto the first space(" ") in string from last RE: Copying random length part of the string. - unbeliever - 12-29-2009 Thanks a lot I will try both of suggested methods RE: Copying random length part of the string. - XeNoMoRpH - 01-04-2010 I tested it and was able to get it to return "4257." Changing it to the following fixed it for me: Code: str = "Change page: < 1 2 3 4 5 6 7 8 9 10 ... > | Displaying page 1 of 426, items 1 to 10 of 4257." That returned "4257" for me. Since I'm not entirely sure how VBScript functions work (in terms of memory usage and processing), it might make sense to do: Code: position = instrrev(str," ") RE: Copying random length part of the string. - unbeliever - 01-07-2010 Thanks for this update This situation is resolved. |