Text match between data row and variable

Hello,

I have this assign:
drCorrespondingRow = dtCorrespondingTab.AsEnumerable.Where(function(x) Regex.Replace(x(0).ToString,“(\r?\n)“,”“).ToLower.Contains(Regex.Replace(strKeyArea,”(\r?\n)”,“”).ToLower)).FirstOrDefault

What this is doing is finding the variable in the data table that is the same as the data row variable. Is there a way of adjusting the to specify a text match? At the moment if the spacing in the variables is different but the text is the same it will come out as no match - what I would like it to do is check the text and see if it matches.

Is there a way of configuring the above code to achieve this?

Cheers

Hi @E.T.S

Try the below syntax:

drCorrespondingRow= dtCorrespondingTab.AsEnumerable _
    .Where(Function(x) 
        System.Text.RegularExpressions.Regex.Replace(x(0).ToString, "(\r?\n)", "").ToLowerInvariant().Equals(
        System.Text.RegularExpressions.Regex.Replace(strKeyArea, "(\r?\n)", "").ToLowerInvariant()
        )
    )
    .FirstOrDefault()

Regards

Hi @vrdabberu

Thanks for your reply.

I am getting the following error message when I apply the suggested logic:

@E.T.S

Can you share the error message?

Regards

image

Cheers

Hi @E.T.S

Try this:

drCorrespondingRow= dtCorrespondingTab.AsEnumerable.Where(Function(x) System.Text.RegularExpressions.Regex.Replace(x(0).ToString, "(\r?\n)", "").ToLowerInvariant().Equals(System.Text.RegularExpressions.Regex.Replace(strKeyArea, "(\r?\n)", "").ToLowerInvariant())).FirstOrDefault()

Regards

1 Like

Thank you that worked!

1 Like

You’re welcome @E.T.S

Happy Automation!!

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