Search array of a word from a text and get the line number of text

Hi All,

  1. I have a set of array stored keyword - {“space”,“versal”,“electronic”,“Regex”)
  1. I have extracted text from OCR - Which looks like below

  2. My bot should look my array keyword in OCR extracted text, if matches found with any one of the array keywords it should get the line number. ex

"versal" - keyword matched with line of “open universal search sentence

The result should be :slight_smile:

The matching word found and the line number is - 3

Could anyone help me, please.
Thanks

Hi there @SrenivasanKanna

You can run LINQ or loop in a loop over the two arrays that you have (for linq convert it to List(of string))

  1. Run loop for your keyword array
  2. Inside the previous loop run your second array (in a loop) while the array has line elements split using \r and find a match (can use contains or something similar {Regex etc})
  3. Break loop once match found

Yeah , I have done this , now i want to get the line number of founded text.

Well,

You can convert your array to list and run this

int indexOfYourLine = yourList.FindIndex(a => a.YourLineString == ThematchedListElement);

the above is in C#.

1 Like

Thanks for your response.

I am not clear what u suggested, I need to get the line number of sentence ocr extracted text, not keywords.

arr keyword = {“space”,“versal”,“electronic”,“Regex”)
arr listkey = keyword.tolist()

ocr extracted text

ocr_text = en command palette\r\ngo to file\r\Open universal search\r\add an activity\r\Go to documentation"

now I need to get the word position of “Open universal search”
Ex : I hope line # start with 0

Answer should be 3

Okay I get it.

So you have two collections now.

  1. Keyword collection
  2. OCR text that is split using the \r char and convert it to list (collection of string)

Run a loop - For each Keyword in your Keyword collection
{
Run another loop - for each line in your OCR text split collection
{

if(your keyword is contained in the OCR item string)
{
then -> assign it to result and BREAK
else -> continue
}
}
}

Hope this helps :slight_smile:

PS : If you want the index you can either keep a recurring count or run the query I suggested in the previous answer.

1 Like

i will try thanks for your replay