Comparing two variables that contain strings in Tasker is harder than expected

953 views
Skip to first unread message

Vitaly

unread,
Nov 20, 2012, 9:57:04 AM11/20/12
to tas...@googlegroups.com
I was trying today to compare two long strings. I thought I could easily do so using the "If" action, however not so: Both "Match" and "Equals" returned false even though the variables contained exactly the same string.

I was eventually able to compare these strings using javascript action that performs the comparison and sets a new global variable with the result. It seems to me, however, that such basic action should be done in an easier way.

Content of the variables that I was trying to compare is available in the following URL: http://pastebin.com/mRmMKMuT

The javascript that I used to actually compare the variables:

var a = global('Forcar');
var b = global('Forcar2');
if(a == b)
{
    setGlobal('JsEq','true');
}
else
{
    setGlobal('JsEq','false');
}



Thanks!
Vitaly

GermainZ

unread,
Nov 20, 2012, 10:01:05 AM11/20/12
to tas...@googlegroups.com
It's because the strings contain "/" which is interpreted as an "or" by Tasker's pattern matching. There is no way to escape these characters yet (it's on the long to do list).

Vitaly Belman

unread,
Nov 20, 2012, 10:03:21 AM11/20/12
to tas...@googlegroups.com
Got it.

Though I think before escaping, I think it would be great if a "StringEquals" action was added then or alternatively make "Equals" working for strings as well.

Thanks!
--
- Vitaly


Michael White

unread,
Nov 20, 2012, 4:21:02 PM11/20/12
to tas...@googlegroups.com
I had the same problem.
I used split var (splitter /), to set 2 local local arrays ( %arra and %arrb ), and then compared %arra() and %arrb().
Avoids the use of javascript, but requires more calculations... 
Reply all
Reply to author
Forward
0 new messages