Finding more than one word on a screen

Hi all

This is probably a relatively easy thing to do but I’m trying to get OCR text and see if a screen contains words, e.g “word” or “another”.

How would I go about doing this? I’ve tried Screen.Contains(“Word”) OR (“Another”) however I get the error of “Option Strict On disallows implicit conversions from ‘String’ to ‘Boolean’.” and Contains is not a member of ‘Boolean’

The “Screen” variable is currently in the Text Output (as opposed to WordsInfo Output).

Any ideas?

Thanks!

It sounds like you have somehow got the incorrect format for the Screen variable. This should be a String format in which case you will be able to do .String. The error message is implying that your Screen variable is a Boolean in which case you cannot use Contains or other text functions.

Hey

Sorry, my bad! The error I get when it’s String is “Option Strict On disallows implicit conversions from ‘String’ to ‘Boolean’.” and when I change it to Boolean, I get the “Contains is not a member of ‘Boolean’” error.

If it makes any difference, this is a condition on an “If” function

So where you have the variable as string the message is telling you that you are trying to convert string to boolean. Can you post your xaml file please? This should be an easy fix.

Here is an example - this uses your first message and checks to see whether it contains OCR.

Main.xaml (7.7 KB)
project.json (243 Bytes)

Richard

Main.xaml (8.4 KB)

This is the one I was trying on a smaller project

Hey

Thanks for this but I want to see if it contains more than one word, this example contains one word to search for.

Hope that makes sense!

Just add an OR and then the same thing with the other word. There is no
option for using the equivalent of IN (item1, item2) etc as far as I know.

If you have a large number of items you can use a loop to check each one.

There is, but you need to reverse the check and see if you have any element with a predicate.

List(Of String) keywords = {"word", "another"} keywords.Any(Function(x) yourText.Contains(x)) // yourText contains any of the keywords in the list keywords.All(Function(x) yourText.Contains(x)) // yourText contains all of the keywords in the list

Which essentially is a loop as well, but can be used in an If condition directly.

Sidenote: @Short - “Screen” is a bad name for a variable, since there actually is a class named like that in a couple of namespaces and you could get conflicts. Try to name your variables more descriptively, f.e. screenReadout or screenText etc.

3 Likes

Thanks @andrzej.kniola :slight_smile:

“Screen” wasn’t the full name for the variable, just used it as an example