Find data row index (n) for search term in data column - Get data rows: n-1, n, n+1, n+2, n+3

Hello, I am looking for some assistance on a datatable process. I have a datatable, called dt_Table. dt_Table has hundreds of rows of data. I need to identify which rows in dt_Table contain a dt_String - “My String” - there will be about a dozen rows which contain the dt_String. Once i’ve idenfitied each instance of dt_String, i need to pull the entire row 1 ABOVE dt_String, and 3 rows BELOW dt_String. As an example:

(0) Data Table Pull
(1) Data1 Table1 Pull1
(2) My String Table2 Pull2
(3) Data2 Table3 Pull3
(4) Data3 Table4 Pull4
(5) Data4 Table5 Pull5
(6) Data5 Table6 Pull6

So I would need to pull the entire row (2) row, as well as (1), (3) (4) & (5)

Please help! thank you

@mbm10
Welcome to the forums

give a try on following

assign activity
LHS: arrIndexes | Datatype Int32() - Integer Array
RHS:

(From x in Enumerable.Range(0, dt_Table.Rows.Count)
Where dt_Table.Rows(x)(YourColNameOrIndex).toString.Contains(dt_String)
Select i=x).toArray

we will get an array with all RowIndexes where the particular column value contains the searched String

Assign activity:
LHS: idx | Int32
RHS: arrIndexes.First()

Assign Activity:
LHS: Result | List(Of DataRow)
RHS:
dt_Table.AsEnumerable.Skip(idx).Take(5).toList

Thank you Peter, I was able to translate this to my process. Much appreaciated.

Perfect. Just do your final testing and close the topic when it was working fine by marking the solving post as the solution.

Forum FAQ - How to mark a post as a solution - News / Tutorials - UiPath Community Forum

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