Extract a chain of characters from text validation

Ranorex Spy, Recorder, and Studio.
damien
Posts: 6
Joined: Wed Jun 24, 2020 8:17 am

Extract a chain of characters from text validation

Post by damien » Wed Jun 24, 2020 8:23 am

Hello,

I'm using the validate function to recognize a text on my UI.
With that I'm extracting the following text: 144 / 177.
I would like to validate the first part of that text ( so only: 144).

My questions are:
* Is there a way to extract these first characters ?
* If yes, can I also extract that way: take only the characters before the "/"
* Can I also re-use that 144 value afterward and use for an other validation (i.e: validation = 144 + 1 )

Thanks a lot for your answers !

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

Re: Extract a chain of characters from text validation

Post by odklizec » Wed Jun 24, 2020 9:33 am

Hi,

You can use regex pattern in GetValue action:

Code: Select all

.+(?=\s/)
Basically, it returns text before space and slash. GetValue will store the text in a variable, which you can use for validation or whatever purpose you want.

In case you want to do arithmetic operations with obtained value, you must convert it to number and perform all operations in user code. There is no way to perform them in recording table. Variables in recording tables are always strings! To convert string to number, you can use for example int32.Parse(variable) method.
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

damien
Posts: 6
Joined: Wed Jun 24, 2020 8:17 am

Re: Extract a chain of characters from text validation

Post by damien » Wed Jun 24, 2020 11:27 am

Thanks for your feedback.
Can you just give me an example and how I can do that ?
Can you also tell me what does mean the characters you mentioned (.+(?=\s/))

Thanks !

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

Re: Extract a chain of characters from text validation

Post by odklizec » Wed Jun 24, 2020 12:39 pm

Hi,

Characters I mentioned in my post are so called 'regular expression'. All you have to do is to add the expression to GetValue action (to regex pattern section), as shown for example here:
https://www.ranorex.com/forum/viewtopic ... 571#p31573
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

damien
Posts: 6
Joined: Wed Jun 24, 2020 8:17 am

Re: Extract a chain of characters from text validation

Post by damien » Wed Jul 01, 2020 10:30 am

Allright I managed it, thanks for the support.

I just add to create an usercode for the validation part