Difference between revisions of "Manual:DIL Manual/right()"
Jump to navigation
Jump to search
(XML import) |
(checked against the compiler and the interpreter; example compiles) |
||
| (One intermediate revision by one other user not shown) | |||
| Line 1: | Line 1: | ||
| + | = right() = | ||
| + | '''Function''' (string). Returns the last characters of a string. | ||
| + | right(s : string, n : integer) | ||
| − | < | + | Returns the last <code>n</code> characters of <code>s</code>: |
| + | <code>right("This is Easy", 4)</code> is <code>"Easy"</code>. | ||
| − | + | == Parameters == | |
| + | {| class="wikitable" | ||
| + | ! Name !! Type !! Meaning | ||
| + | |- | ||
| + | | s || string || The string. | ||
| + | |- | ||
| + | | n || integer || How many characters to take from the end. | ||
| + | |} | ||
| − | + | == Returns == | |
| − | + | String: the last <code>n</code> characters. The whole string when <code>n</code> is its length | |
| − | + | or more; <code>""</code> when <code>n</code> is 0 or less, or <code>s</code> is empty. | |
| − | |||
| − | |||
| − | |||
| − | + | == Notes == | |
| − | + | * <code>right(s, length(s) - 1)</code> is everything but the first character, and | |
| − | + | <code>""</code> for an empty <code>s</code>. | |
| + | * It counts bytes, so a letter outside ASCII (UTF-8) counts as two or more. | ||
| − | + | == Example == | |
| + | <pre> | ||
| + | dilbegin string say_verb(s : string); | ||
| + | code | ||
| + | { | ||
| + | if (right(s, 1) == "?") | ||
| + | return("ask"); | ||
| + | if (right(s, 1) == "!") | ||
| + | return("exclaim"); | ||
| + | return("say"); | ||
| + | } | ||
| + | dilend | ||
| + | </pre> | ||
| + | Picks the verb for something said from its last character, as comm.zon does. | ||
| + | |||
| + | == See also == | ||
| + | * [[Manual:DIL Manual/left()|left()]] | ||
| + | * [[Manual:DIL Manual/mid()|mid()]] | ||
| + | * [[Manual:DIL Manual/length()|length()]] | ||
Latest revision as of 23:04, 14 November 2026
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 emptys.
- 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.