Cannot take difference of Strings; looking for Conversion.

Ranorex Studio, Spy, Recorder, and Driver.
nas
Posts: 5
Joined: Wed Mar 08, 2017 7:01 pm

Cannot take difference of Strings; looking for Conversion.

Post by nas » Tue May 16, 2017 10:34 pm

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.

krstcs
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

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

Post by krstcs » Tue May 16, 2017 11:46 pm

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;
Shortcuts usually aren't...