-->
Page 1 of 3

ANYCASE() String Function

PostPosted: Sun Oct 23, 2016 1:08 pm
by Electroguard
Testing for even a simple "No" flag has the 3 equally valid-looking responses of "no", "No", "NO", but only one will evaluate correctly - leading to a common source of bugs unless all IF tests are impractically tested for all spelling alternatives.

Therefore the addition of an 'ANYCASE()' function could make testing of variables more accurate and foolproof.


EXAMPLE: if Flag_Variable == ANYCASE(response) then gosub[IrrespectiveOfCase] 'would evaluate correctly whatever the case of the response variable.

Re: ANYCASE() String Function

PostPosted: Sun Oct 23, 2016 5:49 pm
by Mmiscool
Use the upper() or lower() functions.

Code: Select allif upper(myvar) == "NO" then print "result true"


https://docs.google.com/document/d/1EiY ... b19oepqhyd

Re: ANYCASE() String Function

PostPosted: Sun Oct 23, 2016 7:51 pm
by Electroguard
Yeah, that's how I have been doing it till now, but I just thought there may be a better way than converting sources variables before comparing to converted target variables, and the result still not an accurate representation of either of the variables case.
Ah well, back to the drawing board.

Re: ANYCASE() String Function

PostPosted: Tue Oct 25, 2016 3:20 am
by livetv
"... I just thought there may be a better way than converting sources variables before comparing to converted target variables..."

I do this:

if lower(response) == "no" then gosub [whyNot]

It seems to be nearly functionally identical to what is being requested. It does require that the "Flag_Variable" in the prior example be all lower case. If you are unsure that this will be the case, just do this:

if lower(response) == lower(Flag_Variable) then gosub [whyNot]

That will work just fine even if it does require two LOWER() functions.

If the intent was to have ANYCASE() resolve any differences between upper and lower case of both the Flag_Variable and the response variable when we don't always know what either might be, then we are out of the realm of a single argument function. We would have to have a function which takes two arguments and compares them OR create a new operator to do it. I would just use two LOWER() functions and be done with it!