Word occurence count in a document

Hi there!
I want to count the number of times a specific word appears in an Excel.
I know there is this post Count Occurrence of word in OCR string but I don’t know where to declare it and it all seems very confusing.

I also have 2 screenshots of my work.
Could you please help me?
Thanks a lot.


Hi Buddy @Alexa_Durdunescu

Kindly follow the below steps that could resolve your issues

  1. To check with number of words in a excel column, first use excel open application scope to open the excel
  2. use Read range activity to read the sheet you want to and get the output with variable of type datatable named out_dt
  3. Still being inside the scope, use a for each row loop with input of out_dt
    now inside the for each row loop use a if condition with condition like
    if the condition passes, in then part of if condition use a counter of default value 0 initialized already like
    in assign activity
    counter = counter + 1

if not in else part leave as it is

This will give the count of the word in the particular column of a excel

Cheers buddy

use the following aString.Count(function(x) x = “theWord”). This returns an integer. You just have to replace ‘aString’ with the name of your variable and ‘theWord’ with the word you’re looking for.

There was a small confusion out there…my bad. I was trying to count the number of times a string appears in a text and write the result(the number of occurences) in the Excel cell.:slight_smile:

well…it doesn t work…

occurencies is of type string

Fine buddy
Can i have a text you have with you for example and the count of string you want to find in it


write cell expects a string. so, use occurencies.count(function(x) x =“pixel”).toString

the workflow now is running but I get zero counts…It can’t be true. I must get at least 2…


I believe the regex will work great if I understand your problem. I’ve written the assignments below for the screenshot attached. The pattern will math only word (for example, if you set wordVariable to “word” it won’t match with “words”) and ignore the case.

String.Format(“\b{0}\b”, wordVariable)

Regex.Matches(textToBeWritten, pattern, RegexOptions.Multiline Or RegexOptions.IgnoreCase).Count

You can directly put the followin as condition in you “If” activity:
Regex.Matches(textToBeWritten, String.Format(“\b{0}\b”, wordVariable), RegexOptions.Multiline Or RegexOptions.IgnoreCase).Count = 0


1 Like

i want to find all the possible cases of the word…like: WORD, Word, Words, WOrds etc…:slight_smile: i will try your suggestion and thank you:)

Then the following should do the trick (don’t forget to import “System.Text.RegularExpressions”):

Regex.Matches(textToBeWritten, wordVariable, RegexOptions.Multiline Or RegexOptions.IgnoreCase).Count = 0

1 Like

thx u both Tiberiu and msan. with your help guys I solved the problem. i still didn’t understand the whole thing with regex and how it works…do you have any recommendations for me to read more about it ? thx

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