Page 1 of 1

Cannot take difference of Strings; looking for Conversion.

Posted: Tue May 16, 2017 10:34 pm
by nas
How do I get the difference of two strings that contain numbers, for example

myDefinedVar = myVar1 - myVar2

is there a convert to number function. I believe when Ranorex variables are defined they are setup as strings. I did get an error stating cannot subtract strings with my UserCode.cs chnages.

Re: Cannot take difference of Strings; looking for Conversion.

Posted: Tue May 16, 2017 11:46 pm
by krstcs
You need to convert them to whatever type of number they are supposed to be, as you have guessed.

Do your values represent integers, longs, doubles, etc.? Can you give an example of what each value might be?


If you are using integers, then you need to use the Parse() method of the "int" class.

Code: Select all

int myValue1 = int.Parse(myVar1);
int myValue2 = int.Parse(myVar2);

int myDefinedVar = myValue1 - myValue2;