Logic of Comparing string functions

Hi guys. This is my problem, and it is so annoying…
My Robot fetch datatable from database, then I use “Get Row Item” to fetch specified value from that datatable and store it in variable type String. After that, I need to check if that variable is “Y” or “N” or empty string. I do that by evaluating condition: String.Compare(Variable,“Y”) = 1 and String.Compare(Variable,“N”) = 1. And it is doing well, but then i realized that function String.Compare return 0 if strings are equal(same) , so i changed conditions to String.Compare(Variable,“Y”) = 0 and String.Compare(Variable,“N”) = 0, and it doesn’t work the way it should. I tested other ways for comparing strings, and it is the same issue.
So,my question is why the result of comparing is wrong, when i know that value of variable is “N” and i compare it with “N” and the result is 1, but it should be 0 because they are same obviously?

Personaly, i think the problem is in type of that variable, because i get it from datatable and it get messed up somewhere in procces, because i tested String.Compare(“Y”,"Y) = 0 and it is working well.

I’m so sorry for making this text so big, but I currently don’t have an idea what do to with this issue.
BTW: the values in database of this column where lies “Y” or “N” is nchar(10).

can you print your string variable and see what value it holds before the condition?
Use a MessageBox activity.

Could it be that the source of your string in the database is not actually “Y” but is left of right padded with blanks? Try Variable.Trim() maybe.

Hi there, i did that, and it shows the right value.

no spaces/characters? put a screen of the value if possible.

Trim both the values and check it @Ta_Rik

Trim worked, thank you guys. I’m so stupid 'cause i didn’t tried trim earlier.

1 Like