Compare first X caracters of rows after if condition

Hello everyone,
I’m new in automation and I need your help please because I didn’t find any solution for my problem.
I have an if condition that will give me some rows as a result and I need to check if these rows have the same X first caracters.
Thank you in advance

Hi @CKJ, welcome to the Community.

Can you provide a sample input & output data, so that we can analyze your requirements clearly?

Best Regards.

if the condition is true I want to check if these rows have tha same first 8 caracters then assign ok to a column named check_Mdp. My datatable is celf and my column is Mdp
1

Hi @CKJ

Take the value that you want to compare the first 8 characters from the column Mdp in a variable called compareStringValue. Then execute the following query in an Invoke Code activity:

io_dt.AsEnumerable.ToList.ForEach(Sub(row)
row(check_Mdp) = if(row("Mdp").ToString.SubString(0,8).Equals(compareStringValue),"Ok",row("check_Mdp").ToString)
End Sub)

This will update all the rows in the Celf data table for every row where the first 8 characters of the data in column Mdp is matched with the desired data.

Hope this helps,
Best Regards.

Thank you so much for your time, I’ll try this and tell you

1 Like

Hi @CKJ

Try this-

  1. Store the rows in a List or DataTable variable.
  2. Use a For Each Row activity to iterate through each row in the List or DataTable variable.
  3. Within the loop you can use the Regex.Match method to extract the first X characters.

For Each Row (row in RowsVariable)

Assign rowString = row("ColumnToCheck").ToString)
Assign firstXChars = System.Text.RegularExpressions.Regex.Match(rowString, "^.{X}").Value

End For Each

Thanks!!

Thank you so much for your response, I dit it with substring

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