Multi Commander > Script
Unexplained if() Behaviour in MultiScript
(1/1)
AlanJB:
Can somebody please explain the behaviour as shown in the debugger output below (Jungle? Mathias? Anyone with a brain younger than mine...?)
The variables' values clearly show that execution should never enter the if(). And yet...
TIA
Alan
Mathias (Author):
Well == works like string compare in c/c++ and other in that it return <0 if string1 is less than string2, 0 if they are same and > if string1 is greater then string2.
So if the result is 0 , there is no changes between the two.. like (($str1 == $str2) == 0)
Been thinking about changing that.. But it would be a breaking change that would break working script..
But you can also use StrIsEqual( str1, str2 ) or StrIsEqualNoCase(str1,str2) they return a 0/1 value
http://multicommander.com/docs/multiscript/functions/string
AlanJB:
Thanks for the reply Mathias.
Yeah - I remember C (never did much C++) and how == works. Are you saying that the MultiScript equality operator actually compares the addresses of the two values, rather than their contents?
So I need to use StrIsEqual() (the equivalent of the C strcmp() function), yes?
I understand if you don't want to change the behaviour - regression testing is a bitch and angry users are even worse :o
I'm very familiar with the MultiScript string functions by now; I spent a couple of hours this morning checking and amending the documentation page for them ;)
Mathias (Author):
No, it does not compare addresses
== is the same a strcmp (c/c++) it returns 0 is both strings are equal. less then 0 or more then 0 depending on how much of the string that matches.
just like http://www.cplusplus.com/reference/cstring/strcmp/
You can turn the == into a boolean response with "(($str1 == $str2) == 0)" if the result of str1 == str2 is 0, then it is true (1), but using StrIsEqual is more readable
StrIsEqual() return a boolean. 0 (false) 1 (true)
AlanJB:
Thanks for the explanation, Mathias.
I clearly had forgotten how strcmp() works after 40 years. That's why I need you youngsters to jog my memory now and again :)
Navigation
[0] Message Index
Go to full version