Manual:DIL Manual/substring()
Jump to navigation
Jump to search
substring()
Procedure. Removes a string from a stringlist.
substring(sl : stringlist, s : string)
Removes the first element of sl that matches s, ignoring case. Only one element goes per call. sl is a stringlist variable or a stringlist field, such as a unit's names. Despite its name, it has nothing to do with parts of a string; for those see left(), mid() and right().
Parameters
| Name | Type | Meaning |
|---|---|---|
| sl | stringlist | The list: a variable or a field. |
| s | string | The string to remove. |
Notes
- An element matches when it is
s, or the first word or words ofs: with{"ship", "boat"},substring(sl, "ship arrived")removes"ship". An element longer thansdoesn't match:"ship"doesn't remove"ship arrived". - When nothing matches, or
sfails, the list stays as it is. - To remove every copy, loop while
s in sl. remove()removes an element by its place in the list.
Example
dilbegin greeter();
var
seen : stringlist;
code
{
:start:
wait(SFB_CMD, (activator.type == UNIT_ST_PC) and (command("say") or command("quit")));
if (command("quit"))
substring(seen, activator.name);
else if (not (activator.name in seen))
{
addstring(seen, activator.name);
exec("say Welcome, " + activator.name + "!", self);
}
goto start;
}
dilend
An NPC that greets each player once, and forgets them when they quit.