Manual:DIL Manual/string

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

string

Type. A piece of text.

var
   s : string;

Strings are written between double quotes: "Hello there". A string variable holds a copy of its text: assigning one string variable to another, or passing a string to a template, copies it. An unset string variable is the empty string "".

Operators

  • + joins strings: "You have " + itoa(n) + " coins.". Both sides must be strings; numbers go through itoa().
  • == and != ignore case: "Sword" == "sword" is true. < > <= >= do not ignore case. strcmp() and strncmp() compare exactly.
  • "key" in s tells whether the first string occurs anywhere in the second, ignoring case (1 or 0).
  • s.[i] is the character at position i (from 0) as a one-letter string. It can be read but not assigned (s.[1] := "x" is "Illegal lvalue").

Notes

  • A " can't be written inside a string: vmc stops at \". Use single quotes in the text.
  • A ^ inside a string ends the program early (see dilend).
  • Reading s.[i] past the end fails and writes "index of stringlist out of bounds" to the zone log; check length(s) first.
  • If any part of a + fails (a field of a null unit, say), the whole result fails, and a sendtext() or assignment with it does nothing.
  • Text sent to players is HTML: lines end with <br/>.
  • String variables keep their value through waits and are saved with the unit.

Example

dilbegin do_shout2(arg : string);
var
   s : string;
code
{
   if (arg == "")
   {
      sendtext("Shout what?<br/>", self);
      quit;
   }
   if ("password" in arg)
   {
      sendtext("Better not.<br/>", self);
      quit;
   }
   s := toupper(arg.[0]) + right(arg, length(arg) - 1);
   act("$1n bellows, '$2t!'", A_ALWAYS, self, s, null, TO_ALL);
   quit;
}
dilend

A command that refuses some words, gives the text a capital letter and shows it to the room.

See also