HOW TO only get the integer value from a string?

Best practices, code snippets for common functionality, examples, and guidelines.
mghali
Posts: 26
Joined: Fri Jul 18, 2014 9:05 pm

HOW TO only get the integer value from a string?

Post by mghali » Wed Aug 19, 2015 3:43 pm

Hello,

I have this scenario where the controltext contains the count of the elements in the groupbox. How can I get the value? I will then need this value to put in a condition loop. I have attached the snapshot for the same

The version I am using is 5.4.0.


Thank you in advance
Attachments
numbers from controltext.rxsnp
(76.18 KiB) Downloaded 86 times

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3914
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: HOW TO only get the integer value from a string?

Post by odklizec » Wed Aug 19, 2015 4:11 pm

Hi,

You can for example use GetValue action, with capture regular expression like this:

Code: Select all

\((.*?)\)
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

mghali
Posts: 26
Joined: Fri Jul 18, 2014 9:05 pm

Re: HOW TO only get the integer value from a string?

Post by mghali » Wed Aug 19, 2015 4:14 pm

I am sorry I do not understand what that means. I am really bad at code

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3914
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: HOW TO only get the integer value from a string?

Post by odklizec » Wed Aug 19, 2015 4:24 pm

You don't have to code anything. Just Add GetValue action to your recording module (either via "add new action" combo or by drag&drop of existing repository element to recording table). Then add the suggested regex to capture regex field and of course, set new module variable where the result of GetValue action will be stored and which could be then used anywhere you want.

However, if you want to use the obtained value as integer value, you will have to convert the string to integer! GetValue always returns string value, no matter if the obtained value looks like number ;) For the conversion of string to integer you can use for example this code:
int numVal = Int32.Parse(varFromGetValue);
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration