How to match the word only with the whole words(String) in uipath?

when trying to match a word in the string, only whole words need to be checked (For Ex: when “MALE” word is searched and it should search for only “MALE”, it shouldn’t match in the word “FEMALE” which also contains MALE in it). Without using Regex.

Hey! Welcome to community!

We can do like this

Variable.Equals("MALE")

Use this in if condition

Then block you will get the MALE
Else block you will get the FEMALE

Regards,
NaNi

(string.contains(“male”)) and not string.contains(“female”)

use this condition

if I searched for the MA word with a string, it can be found in many words like match, mammoth, sumanth etc can’t be done like you said. That can’t be generalized.

i using “.contains” to match the word with the string, variable.equals() can’t be used while matching.

Hey!

If you are using the contains the FEMALE and MALE. Both the strings will come…

If you use equals whenever the match found this will returns the true value…

Contains: Checks the match in the entire string if found returns the true

Example: 1

Input: All ARE FEMALE

Expression: Input.Contains("MALE")

Result: TRUE

Reason: In the above input string contains the MALE.

Example: 2

Input: FEMALE

Expression: Input.Equals("MALE")

Result: False

Reason: The above string not matching with the searched value.

Equals: Equals match with the entire string

Example: 1

Input: MALE

Expression: Input.Equals("MALE")

Result: TRUE

Reason: The string matching with the searched string.

Example: 2

Input: All ARE FEMALE

Expression: Input.Equals("MALE")

Result: FALSE

Reason: Not matching with the searched string

Regards,
NaNi

Hello @Umaprashanth_J

Are you trying to check for some predefined strings? If yes, it would be better to use “IsMatches” activity. You can provide the regular expressions to match only the exact word. If you are using contains, then you will have to use if conditions to verfiy it again.

Thanks

Hi Thiru I have 2 strings which I am trying to compare and I use this script
If PrimarySkuDescriptionClean.equals(ExcelSkuDescriptionClean)

I convert both into string. I did a log message and compared the values and they are the same. (see values below), but they come up as not equal

12/06/2022 19:42:42 => [Info] EXPORT A ULTRA SMOOTH KS./25’S
12/06/2022 19:42:42 => [Info] EXPORT A ULTRA SMOOTH KS./25’S
12/06/2022 19:42:42 => [Warning] EXPORT A ULTRA SMOOTH KS./25’S does not match EXPORT A ULTRA SMOOTH KS./25’S
12

Can you help?

Hi! Welcome to community…

In your case both the strings are different. As I noticed PrimarySkuDescriptionClean Does not equals to ExcelSkuDescriptionClean.

First string contains Primary
Second string contains Excel

So both are not equals.

If you want to compare exact values in both the strings at that point we can use Equals

If you want to check if particular string is present in the target string we can use contains

I’ll suggest you to create new thread.

Regards,
NaNi

Hi Thani
Thank you, what I’m doing is follows.

read 1st column of excel(primary), then assign to variable1 as string.
read 2nd column of excel(secondary) then assign to variable2 as string.

Then assign variable1.trim → variable1clean
Then assign variable2.trim → variable2clean

Then condition

If variable1clean.equals(variable2clean

then do Else (For some reason it goes in the else
even though its equal.

Note we did a log message to trace the values and they are both the same.

Here is an example of how you can use this method in UiPath:


Dim input = "The cat is MALE."
Dim punctuation = input.Where(Function(x As Char) Char.IsPunctuation(x)).Distinct().ToArray()
Dim result = input.Split(" "c).Select(Function(x As String) x.Trim(punctuation)).Contains("MALE", StringComparer.OrdinalIgnoreCase)

If your string contains a space before “MALE” try below condition
YourString.Contains(" MALE")