How to check whether the string in datatable is completely included?

If I have a person’s name, how to check whether the string in datatable is completely included?

Name:Bryson Sean Velazquez

Name Result
Bryson Velazquez X
Sean Adames X
Evan Mulligan X
Bryson Sean Velazquez O
Bryson Sean Zaiden Velazquez O
Zaiden Teller X

Could you do me a favor?THX~

Not sure what you’re asking. Are you asking how to find out if the string exists in the datatable?

1 Like

Hi @Bosch

If you want to check whether the person name present in the datatable or not then you can use this linq query.
nameExists = dataTable.AsEnumerable().Any(Function(row) row.Field(Of String)("Name") = personName)

Here personName is a string variable contains the person name.

2 Likes

Hi @Bosch

If you want to check whether the string name is included in the datatable, use lookup datatable activity to check whether the given value (ie the string ) exists in a particular column. The output of this lookup datatable activity is row index of the row where the given column contains the value , for which it’s value is -1 when the given column does not contain that value. You can use if condition for that rowindex value accordingly

Hope this helps

Mark it as solution if it resolved your query

Thanks and Regards
Nived N
Happy Automation

1 Like

Hi @Bosch ,

From the data available and results mentioned, we can understand that if all the words in the name are present in the Datatable column values, then it is an acceptable case.

Hence, we can first split the Name with Space, so we get the array of words. Then we check if all the words are present in the column cell and then mark the result accordingly.

  1. Splitting of the word to an Array :
wordsInNameArray = Split(Name).ToArray

Here, wordsInNameArray is a variable of type Array of String, Name is a String variable.

  1. We can then use the For Each Row in Datatable activity and loop through each of the rows in the Datatable and perform a Check using an If activity with the below condition :
wordsInNameArray.All(Function(x)CurrentRow("Name").ToString.ToLower.Contains(x.ToLower))

In then part, you can update the Result column as True or the symbol you want to add.

CurrentRow("Result") = "True"

In the else, bloc you can add false :

CurrentRow("Result") = "False"
1 Like

According to the provided name, compare the information in the datatable.The rules are shown in the table. Thanks so much for your help.

It work fine. I’m forever indebted to you for this big favor. Thanks.

1 Like

You don’t need the .ToArray - Split already returns an array. And it’s good practice to explicitly define the split character:

Split(Name," ")

1 Like

Thank you. That’s very kind of you.

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