Count Occurrence of word in OCR string

Hi @aksh1yadav, @DanielHolmes ,
I have extracted data using OCR and saved it as string variable.Now when I am counting the occurrence if word in the string it is giving me 64 but the count i need should be 5. Please find below the image and logic i have used and provide quick help on this.
OCRCapture1
Capture3
Occurence

thanks!

Hi @somya177,

Try this code,

Countword=entirePDF. ToString().Split(Environment.NewLine.ToArray, StringSplitOptions.RemoveEmptyEntries).Length

Or

Countword=entirePDF. ToString().Split(Environment.NewLine.ToArray, StringSplitOptions.RemoveEmptyEntries).Contains("Development").Length

Regards,
Arivu

1 Like

No need to split (which could create a lot of memory allocations) - use Regex.Matches:

int developmentOccurrences = Regex.Matches(myText, "Development", RegexOptions.Multiline Or RegexOptions.IgnoreCase).Count

SIdenote: Or operator is used to combine enum flags (since we want both Multiline and IgnoreCase). Do note that since enums are combined with bit operations they use different logic.

2 Likes