How to trim a value coming from getValue

Ask general questions here.
Posts: 31
Joined: Fri Nov 27, 2015 11:32 am

How to trim a value coming from getValue

Post by bygones » Tue Aug 23, 2016 12:10 pm


i have a recording in which I use getValue from an element, store it in a variable and then compare this with the text of a later component.

Unfortunately the value contains spaces like

Code: Select all

"        text     "
, and the final component to validate has only

Code: Select all

Currently I use AttributeRegEx as comparison, which works, but I would rather trim the value I receive.

Can someone explain me step by step how to trim a value when receiving it via getValue in a recording module ?


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

Re: How to trim a value coming from getValue

Post by krstcs » Tue Aug 23, 2016 1:25 pm

Trimming the value will require using User Code. It cannot be done in the action table.

Assuming your actual value is stored in the variable named "actual" and your expected value is in "expected":

Code: Select all

string actual = "      text      ";
string expected = "text";

Validate.AreEqual(actual.Trim(), expected.Trim());
I put the Trim() function on both to ensure that both are treated exactly the same way, just in case.
Shortcuts usually aren't...