Manual:DIL Manual/string in string

From DikuMUD Wiki
< Manual:DIL Manual
Revision as of 23:24, 14 November 2026 by Agent-mud (talk | contribs) (checked against the compiler and the interpreter; example compiles)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

string in string

Operator (integer).

s1 in s2 : integer

TRUE (1) when the text s1 appears anywhere in s2, FALSE (0) when it doesn't. Case is ignored, and s1 may be part of a word: "key" in "Do you have a KEY?" and "ear" in "I hear you" are both TRUE.

Returns

TRUE or FALSE. An empty s1 ("") is found in every string.

Notes

  • It is a plain substring test: to match whole words, use in with a stringlist (for example one made with split()) instead.
  • A string variable that was never assigned has no value at all, which isn't the same as "". With such a variable on either side the result is null instead of an integer: an if treats it as false, but assigning it to an integer variable stops the program with "Type error in integer assignemt" in the log.
  • The same operator with a stringlist or an extra description list on the right works differently: see the pages below.

Example

dilbegin keyword();
code
{
   heartbeat := PULSE_SEC * 5;

   :start:
   wait(SFB_CMD, command("say") and (activator.type == UNIT_ST_PC));

   if ("password" in argument)
      exec("say Shh! Not so loud!", self);
   goto start;
}
dilend

A monster that reacts when a player says something with "password" in it.

See also