Count Occurrence of word in OCR string


#1

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!


#2

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


How to get position of text where the mouse clicks
#3

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.
https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/operators/logical-bitwise-operators