Manual:DIL Manual/right()

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

right()

Function (string). Returns the last characters of a string.

right(s : string, n : integer)

Returns the last n characters of s: right("This is Easy", 4) is "Easy".

Parameters

Name Type Meaning
s string The string.
n integer How many characters to take from the end.

Returns

String: the last n characters. The whole string when n is its length or more; "" when n is 0 or less, or s is empty.

Notes

  • right(s, length(s) - 1) is everything but the first character, and
 "" for an empty s.
  • It counts bytes, so a letter outside ASCII (UTF-8) counts as two or more.

Example

dilbegin string say_verb(s : string);
code
{
   if (right(s, 1) == "?")
      return("ask");
   if (right(s, 1) == "!")
      return("exclaim");
   return("say");
}
dilend

Picks the verb for something said from its last character, as comm.zon does.

See also