String comparision and returning mismatched

Hi,

I have two names and I should return the mismatched letter

John Antony

Jonh Antony

output is - nh

Hi,

you can use the following regex pattern to find the difference between two strings:

[^ \w]+

This pattern matches any non-word character that is present in the first string but not in the second string.

Here’s how you can use this pattern in UiPath:

  1. Create two string variables “originalString” and “modifiedString” and assign the values “John Antony” and “Jonh Antony” respectively.
  2. Use the “IsMatch” activity to check if the two strings are different. Set the “Input” property to “originalString”, set the “Pattern” property to the regex pattern mentioned above and set the “IgnoreCase” property to “True”. This activity will return a boolean value that indicates whether the two strings are different.
  3. If the two strings are different, use the “Replace” activity to remove the common characters from the first string. Set the “Input” property to “originalString”, set the “Pattern” property to the same regex pattern mentioned above, and set the “Replacement” property to an empty string. This activity will return the difference between the two strings.
  4. Display the difference in a message box or store it in a variable for further processing.

When you run this workflow with the input strings “John Antony” and “Jonh Antony”, the output in the message box will be “nh”.

Cheers @joe2

@joe2

similar to your other topic we would recommend also to specify different scenarios e.g. different string lengths etc.

Have a look here:
grafik

1 Like

Hi @joe2 ,

Maybe the same methods but with slight variations :

new String("Jonh Antony".Where(Function(x,i)Not("John Antony".Substring(i,1).Equals(x.ToString))).ToArray)

image

Actually I am comparing certain names and i have to return the character which are mismatched

more examle scenario are as follows;

Rock Thomas

Rock Tomas
O/p-h

zose Jose
ose Jose
o/p-z

even in the above scenarios the name
John Antony

Jonh Antony

nh have replaced the places so output is nh

String Compare- mismatched string.xaml (13.3 KB)

For the current input string both doesn’t work. kindly help

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