Chapter 19: Advanced Text
19.5. Matching and exactly matching

Up to now, we have only been able to judge two texts by seeing if they are equal, but we can now ask more subtle questions.

if WHATEVER matches the text FIND, ...

tests whether FIND occurs anywhere inside WHATEVER. For instance:

if "[score]" matches the text "3", ...

tests whether the digit 3 occurs anywhere in the score, as printed out; and

if the printed name of the location matches the text "the", ...

tests to see whether "the" can be found anywhere in the current room's name. Note that the location "Smotheringly Hot Jungle" would pass this test - it's there if you look. On the other hand, "The Orangery" would not, because "The" does not match against "the". We can get around this in a variety of ways, one of which is to tell Inform to be insensitive to the case (upper or lower) of letters:

if the printed name of the location matches the text "the", case insensitively
begin;
    ...
end if.

We can also see how many times something matches:

number of times WHATEVER matches the text FIND
number of times WHATEVER matches the text FIND, case insensitively

This may be 0, of course. Here the matches involved are not allowed to overlap: so "aaaaaaaa" matches the text "aaaa" twice, not five times, even though it occurs at five different positions.

Finally we can also insist on exact matching, like so:

WHATEVER exactly matches the text FIND
WHATEVER exactly matches the text FIND, case insensitively

Here the match has to start at the front and finish at the end, and there's no "number of times WHATEVER exactly matches the text FIND" since this is by definition going to have to be 0 or 1. Of course,

WHATEVER exactly matches the text FIND

could be more simply phrased as "WHATEVER is FIND", since what it does to compare the two texts character-for-character. But in the next section we shall see that "matches" and "exactly matches" can do much more than the simple text matching demonstrated above.


PreviousContentsNext