Manual:DIL Manual/left()
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 ....