Forcing string comparisons, or When is "0" not 0?

Devin Asay devin_asay at byu.edu
Wed Oct 14 17:01:46 EDT 2015


> On Oct 14, 2015, at 2:40 PM, Dr. Hawkins <dochawk at gmail.com> wrote:
> 
> On Wed, Oct 14, 2015 at 1:19 PM, Devin Asay <devin_asay at byu.edu> wrote:
> 
>> Shouldn’t there be a way to force a string comparison? I know LC tries to
>> be all helpful about casting numerals as numbers, but what if I want to
>> know if it’s the exact string?
>> 
> 
> if (space & field "Display" ) = (space & someValue) then  . . .

Believe it or not, when field “display” contains “0.”, the following evaluates to TRUE:

  if (space & fld “display”) = (space & “0”) then … # TRUE!

And even:

  if (space & fld "display" & space) = (space & "0" & space) then … # TRUE AGAIN!

It’s the space that’s the problem. Any other character seems to do the trick:

  if ("!" & fld "display") = ("!" & "0”) then … # FALSE

Try explaining that to newbies. “Oh, I’m just coercing LiveCode to cast the field contents as a string instead of a number.”

Blank stares and crickets… :)

Devin


Devin Asay
Office of Digital Humanities
Brigham Young University



More information about the use-livecode mailing list