Compare Strings using if statement

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
aqua267
Junior Coder
Posts: 27
Joined: Thu Aug 19, 2010 7:57 pm

Compare Strings using if statement

Post by aqua267 » Tue Jan 04, 2011 4:00 pm

I am trying to compare two strings and call a subroutine if the strings are equal. The code always goes to else statement even if the strings are the same.
My code snippet

Let>Name="This is test"
//From my application, I am getting GetName
GetClipBoard>GetName
wait>0.5
if>GetName=Name
GoSub>GoHere
else
Print a message
endif

The code always hits the Print a message even when GetName's value is same as Name. Please help!

Thanks.

User avatar
JRL
Automation Wizard
Posts: 3517
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Tue Jan 04, 2011 4:05 pm

Whatever text you test for has to match EXACTLY. Case and characters.

"This is test" will not match This is test nor will it match "this is test". Step through your code in the editor and examine the watchlist to be sure you are getting exact matches. Also Watch for trailing spaces.

Jerry Thomas
Macro Veteran
Posts: 267
Joined: Mon Sep 27, 2010 8:57 pm
Location: Seattle, WA

Post by Jerry Thomas » Tue Jan 04, 2011 5:23 pm

BTW, one common technique to simplify this, is to convert both strings to upper case before comparing.
Thanks,
Jerry

[email protected]

aqua267
Junior Coder
Posts: 27
Joined: Thu Aug 19, 2010 7:57 pm

Post by aqua267 » Tue Jan 04, 2011 7:11 pm

Thanks for the replies. It appears there was a trailing space. I trim it now before comparing.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts