Why does this return false: str_RecWrt.equals("Record was written.")

I have confirmed that the value in str_RecWrt is indeed “Record was written.”. Several times.

Why does this always return false?!?!

c1

@Bryan_Schmiedeler - If there is any additional spaces in that string…try using

.trim

@Bryan_Schmiedeler

Check below

If you are getting False that means there are some space where you are not able to identify

Use Trim option to remove unwanted space

str_RecWrt.Trim.equals(“Record was written.”)

Hope this helps you

Thanks

Hi @Bryan_Schmiedeler,

Just to add to the answers from @prasath17 and @ksrinu070184 i.e., to use string.trim.

Another simple trick is to always explicitly match your string with either upper case or lower case converts. That way, if we are not interested in the string case, we always will get matches correctly (apples to apples comparison).

For example:
str_Reference = "Record was written."
str_RecWrt.ToLower.Trim.Equals(str_Reference.ToLower) OR str_RecWrt.ToUpper.Trim.Equals(str_Reference.ToUpper)

UpperLowerCaseMatch.xaml (6.3 KB)

So I tried Trim and it still didn’t work. Was driving me crazy.

I had an idea that it might be invisible characters. Check the web site and the 2 spaces in the phrase “Record is written.” are &NBSP - non breaking spaces. So I wrote something to display the ASC characters and compare them. Yup, the text from the web has a 160 in it and the literal string has a 32! So the strings are not equal.

I found a routine on UiPath Connect called Remove Non ASCII Chars. This is almost just what I need. I downloaded it and will modify it so that I also do a full trim and a Case. Maybe I can make a function that accepts two strings and returns true or false after applying all this cleaning. I am pretty new to UiPath so not sure how to do this. Ideally I would want a function called textOnlyCompare that took 2 strings , stripped off all the crap, did a Ucase compare and returned either true or false.

c2 ca

1 Like

Hi @Bryan_Schmiedeler,

That is an interesting finding. I agree that using the already implemented solution is the way to go. So to the last part of your question.

Here is a function you were interested in.

I have not uploaded the Remove Non ASCII Chars.xaml as I want people to download it directly from UiPath connect. You therefore wlll have to fix the Invoke Workflow in this attached file. Just direct it to your version of Remove Non ASCII Chars.xaml.
textOnlyCompare.xaml (11.6 KB)

Usage: You can invoke the textOnlyCompare.xaml in any other workflow (in the same project folder). On runtime, it will invoke the Remove Non ASCII Chars snippet and after removing the ASCII characters will go ahead and process the string with .Trim and .ToUpper.

Finally, we use a IF condition to check if the source string (which has been processed) is equal to the reference string.Trim.ToUpper

If yes, return a boolean flag back to your main workflow where you invoked textOnlyCompare.xaml.

A quick look at the workflow.