Page 1 of 1

HOW TO only get the integer value from a string?

Posted: Wed Aug 19, 2015 3:43 pm
by mghali
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

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

Posted: Wed Aug 19, 2015 4:11 pm
by odklizec
Hi,

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

Code: Select all

\((.*?)\)

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

Posted: Wed Aug 19, 2015 4:14 pm
by mghali
I am sorry I do not understand what that means. I am really bad at code

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

Posted: Wed Aug 19, 2015 4:24 pm
by odklizec
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);