On Fri, 19 Aug 2016, Sven Schreiber wrote:
it often occurs (at least in my own and in Artur's hansl programming) that
you want to check whether a certain string variable contains some shorter
string. For example whether variable 's1' contains the string "USA",
being necessarily exactly equal to "USA".
Currently to my knowledge this can/must be done using the strstr() function,
either like this (producing non-negative integer output):
or like this:
strstr(s1, "USA") != ""
I find both variants relatively clumsy, so I'm asking for syntactic sugar
which would be equivalent to the second expression above. For example an
'instring()' function that would be loosely analogous to the inbundle() or
So the above example would simply be rewritten as:
But maybe Jack or somebody else have an alternative suggestions what could be
done instead with existing hansl constructs.
How about if we emulated C (sort of) and allowed empty and non-empty
strings to evaluate as 0 and 1 where the context requires a Boolean
result? Then you could just say
if strstr(s1, "USA")
# something else
(Strictly, in C "strstr(s1, s2)" in a Boolean context is equivalent to
"strstr(s1, s2) != NULL". But we don't have truly NULL strings
floating around in hansl, and emptiness seems like the moral