Manual:DIL Manual/left()

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

left()

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

left(s : string, n : integer)

Returns the first n characters of s: left("shorten me", 5) is "short".

Parameters

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

Returns

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

Notes

  • It counts bytes, so a letter outside ASCII (UTF-8) counts as two or more, and can be cut
 in half.

Example

dilbegin string shorten(s : string, n : integer);
code
{
   if (length(s) <= n)
      return(s);
   return(left(s, n - 3) + "...");
}
dilend

Shortens a long text to n characters, ending in ....

See also