Page 1 of 1

Litterals, strings and operators

Posted: Sat Jun 02, 2018 5:12 am
by Meeply
Just want to make sure I understand here.

If I did something like

Code: Select all

/varset ShortName ${Me.Class.ShortName}
/if (${ShortName} == "NEC") |** with or without the quotes **|
the code will fail. When checking the wiki, I looked at operators and see the obvious == for equal but do not see which data types will work with it. Do I assume it is only ints and maybe bools (depending on how they are treated)? Can I assume then that none of the operators listed work on TLOs other than these types? (Clearly operators that are mathematical in nature would not work like bit shifts etc.)

It would seem there are at least 2 options I have found to compare strings; ${String.Equal[litteral - no quotes]} or to check to see if it is a member of a group with ${Select[${ShortName}, NEC, BLAH, ETC]}. Based on my checking macros, these are both not case sensitive. I believe I saw a case sensitive version with String.EqualCS (memory fails if I spelled that right atm). Just for completeness is there a case sensitive version of select or would you have to add an additional toupper or tolower equivalent to get it to work?

How hard would it likely be to put in ==, != overrides like C++ for objects other than ints?

Am I getting the syntax right or am I missing something?

Thanks in advance.

Re: Litterals, strings and operators

Posted: Sat Jun 02, 2018 9:03 am
by SwiftyMUSE

Code: Select all

${Me.Class.ShortName.Equal[NEC]}

Re: Litterals, strings and operators

Posted: Sat Jun 02, 2018 5:15 pm
by Meeply
I see code like that all the time and in one sub I was trying to save cycles but having to reevaluate Me.Class.Shortname part as just save it as a litteral. Then the comparisons should be more simple. I don't know how much faster (probably negligible) but less to evaluate using my var ShortName (a string) at least using

Code: Select all

${ShortName.Equal[NEC]}

then got interested in the topic in general seeing a lot of Selects as well just for a non 0 value. Just was unclear why the operators did not discuss which data types they operated on as a concept. Yes, I get it was a micro optimization that probably did very little but repeated code and evaluations are also something I try to avoid.

Thanks.

Re: Litterals, strings and operators

Posted: Sun Jan 18, 2026 11:33 am
by xyilla