How to get the number of times a text appear on the screen

I’m using get text to capture the screen of the terminal, and set the output as ab.
TEXT1 is the text I want to capture on the screen.

What would the coding be if I want to check the no. of times the word TEXT1 appear on the screen, is it by using contains?

@christine.tzenghy
can be done with RegEx Matches

1 Like

@christine.tzenghy Use Matches activity and pass your Input String and pattern as TEXT1
then use assign activity to get the count of matches like result.Count.ToString
image

Hi @Arpit_Kesharwani

Can I use something like this?

ab.Contains(“TEXT1”).Count.ToString =“1”

I got an error which state that count is not a member of boolean after trying to run the code.

Use Matches activity
image
image

What would be the input ?

Output of the get text?

Input would be ab in your case and output will be a collection
You need to get a count of Matches via assign activity
like result.count.ToString

Hi @christine.tzenghy,

Check this

count = strVar.Split(" "c).Count(Function(c) c.ToString().ToLower() = "text1")

@Arpit_Kesharwani Thanks but I got the below error after trying

Compiler error(s) encountered processing expression “result.Count.ToString”.
‘String’ cannot be converted to ‘System.Collections.Generic.IEnumerable(Of System.Text.RegularExpressions.Match)’ because ‘Char’ is not derived from ‘System.Text.RegularExpressions.Match’, as required for the ‘Out’ generic parameter ‘T’ in ‘Interface IEnumerable(Of Out T)’.

can you share the screenshot of workflow

@Arpit_Kesharwani

Sorry I couldn’t share the workflow. Do you mind to tell me what should be the variable type of result?

@christine.tzenghy yes please share

@Arpit_Kesharwani What should I put the variable type of “return” variable? Is it a string?

@christine.tzenghy No its not a string. Just press ctrl+k in the Result, It will create a new variable of type IEnumerable

@Arpit_Kesharwani Thanks so much, it is working now.

1 Like

@christine.tzenghy :hugs: Can you please mark the reply as a solution :star_struck:

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.