Manual:DIL Manual/mid()

From DikuMUD Wiki
< Manual:DIL Manual
Revision as of 23:04, 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

mid()

Function (string). Returns the characters from one position to another.

mid(s : string, first : integer, last : integer)

Returns the characters of s from position first to position last, both included, counting from 1: mid("sprocket", 3, 6) is "rock".

Parameters

Name Type Meaning
s string The string.
first integer Position of the first character to take; 1 is the start.
last integer Position of the last character to take.

Returns

String: the characters from first to last. A first below 1 counts as 1 and a last past the end as the end; when first is past the end the result is "". When last is smaller than first it fails and writes Illegal: mid(1,2,3) 3 > 2 to the zone's log; a string variable assigned the result is then empty.

Notes

  • The third argument is a position, not a length: mid(s, 5, 2) is an error (or
 "" when s is shorter than 5).
  • It counts bytes, so a letter outside ASCII (UTF-8) counts as two or more.

Example

dilbegin string stamp(line : string);
code
{
   // asctime(realtime) is like "Sat Nov 14 12:34:56 2026": characters 12 to 16 are "12:34"
   return(mid(asctime(realtime), 12, 16) + " " + line);
}
dilend

Puts the time of day in front of a line, as the logs in commands.zon do.

See also