Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Copying random length part of the string.
#1
Solved: 11 Years, 3 Months, 3 Weeks ago
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!
Reply
#2
Solved: 11 Years, 3 Months, 3 Weeks ago
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.
Reply
#3
Solved: 11 Years, 3 Months, 3 Weeks ago
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."
num = mid(str,instrrev(str," "),len(str)-1)
msgbox num

correction - you can take trim your value upto the first space(" ") in string from last

Reply
#4
Solved: 11 Years, 3 Months, 3 Weeks ago
Thanks a lot Smile

I will try both of suggested methods
Reply
#5
Solved: 11 Years, 3 Months, 3 Weeks ago
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."
num = mid(str,instrrev(str," "),len(str)-instrrev(str," "))
msgbox num

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," ")
num = mid(str,position,len(str)-position)
instead.
Reply
#6
Solved: 11 Years, 3 Months, 3 Weeks ago
Thanks for this update Smile

This situation is resolved.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  VB Script - random string qtp_user22 5 26,942 06-19-2014, 04:54 PM
Last Post: roysam404
  How to extract part of a string between two particular characters. ACCBAJPA 7 5,750 08-22-2013, 02:39 PM
Last Post: ACCBAJPA
Exclamation Retrieve the complete height and width of a browser beyond the visible part as wel learnQtptips 0 2,114 05-22-2013, 09:36 AM
Last Post: learnQtptips
  how to get mantissa and decimal part Ishul 3 4,108 03-28-2012, 10:40 PM
Last Post: Surya
  How to have a variable that has a string comma string .. shareq1310 5 5,075 11-09-2011, 03:33 PM
Last Post: parminderdhiman84

Forum Jump:


Users browsing this thread: 1 Guest(s)