Extract data from datatable that matches condition to maximun of 10 matches

Hi all, I need help to extract data from a data table and print book titles that contain the word “science” but I can only have a maximum of 10 matching entries that contain the word “science”.

so far I have:
for each row in data table
if row.item(0).ToString.Contains(“science”)
then print value.

I’m not sure how to stop printing after 10 matches of the book title containing the word “science” I would really appreciate the help!!


Welcome to our UiPath community.

Let’s say your input DataTable is dtInput

           dtOutput = dtInput.AsEnumerable.Where(Function(row) row(0).ToString.Trim.ToLower.Contains("science")).Take(10).CopyToDataTable
1 Like

Would I put that in my if statement?



Use Assign activity.

Leftside: dtOutput
Rightside: dtInput.AsEnumerable.Where(Function(row) row(0).ToString.Trim.ToLower.Contains("science")).Take(10).CopyToDataTable

Above expression will give top 10 matching rows as output from input DataTable. Here, dtOutput variable is of type DataTable.

@hurricane_700 Use break activity after 10 matches

Hi @hurricane_700 ,

If you want the Output in the form of a String, where all 10 values containing science is combined then we could try using the Below Expression :

String.Join(",",DT.AsEnumerable.Where(Function(row) row(0).ToString.Trim.ToLower.Contains("science")).Take(10).Select(Function(x)x(0).ToString.Trim).ToArray)


Using the For Each Row, we can assign a Integer variable as the index and Use it in If Condition to Check if is Equal to the Count needed and then exit the loop using Break.

Thank you this worked!

1 Like