If text exist, get number next to it


#1

What is the best way to do this:

If a given text exist the robot should store the number next to the text as a variable.


#2

Do you have an example text with the number and is it consistent?

If it’s consistently like “abc 123”, then you can simply use .Split()
If text.Contains(“abc”) Then
Assign num = text.Split(" "c)(1)

If it’s not consistent you might look into using Regex instead to pull the number out.


#3

Hello!

There’re a couple ways to do this.

Here’s some activities that can do what you want:
image

All of those activities returns a True/False value. So, with a condition Activity (If) you can compare what you want and then can get the text from the next field that you need.


#4

Will this work if the screen is a picture?


#5

You can use “Image exists” or “OCR Text Exists” if you’re working with pictures :smiley:


#6

ABC will be consistently, the numbers change.

It will be like this:

Bilag 123456

Could the number be replaced by * or ? ?


#7

Since it’s consistent, you might just use the .Split method to keep it simple.

First you need to store the text with Get Text or OCR Text.

Then,
Assign num = text.Split({" "},System.StringSplitOptions.RemoveEmptyEntries)(1)

Maybe something like that. I’m sure there are other good solutions too.


#8

Maybe there is something i’m missing, but how to i get that specific text that i want?

I have screen scraped the entire page/picture, but how to tell the robot to get the specific text i’m looking for.


#9

If it’s an image, then you need to get all the text in the image with OCR Text. After that you need to find a keyword and split out to the text you are looking for.

For example if “text” is the text you scraped with OCR Text,
num = text.Split({“keyword”},System.StringSplitOptions.None)(1).Trim.Split(vblf(0))(0)

vblf(0) is newline character

If it’s not an image then you could Get Text of the element instead.

So in short, you need to extract the chunk of text, then find the word you want with .Split and a keyword.

Regards!


#10

Have you tried via Citrix Recorder -> Screen Scraping -> Scrape Relative?

While it may not exactly solve your question (or maybe it does) it definitely will generate a workflow sample for you from which you can try to adopt it. Knowing how to scrape a region to relative to an image is essential with Citrix-type automation.


#11

Will scrape relative work if you have to scroll down to find the text?