Difference between revisions of "Manual:DIL Manual/right()"

From DikuMUD Wiki
Jump to navigation Jump to search
(XML import)
(checked against the compiler and the interpreter; example compiles)
 
Line 1: Line 1:
−
<span id="bfright"></span>
+
= right() =
 +
'''Function''' (string). Returns the last characters of a string.
  
−
  '''Function:'''  <i><!--CODE-->string right ( o : string, r : integer );</i><!--ENDCODE-->
+
  right(s : string, n : integer)
  
−
<!--TERM--> '''o'''
+
Returns the last <code>n</code> characters of <code>s</code>:
−
<!--DEFINITION-->         the original string to be parsed
+
<code>right("This is Easy", 4)</code> is <code>"Easy"</code>.
−
<!--TERM--> '''r'''
 
−
<!--DEFINITION-->         The amount of characters to parse out
 
−
<!--TERM--> '''return'''
 
−
<!--DEFINITION-->         the right portion of the string with length r
 
  
−
This function parses the string passed to it and returns the number of characters
+
== Parameters ==
−
from the right defined in its second argument.
+
{| class="wikitable"
−
'''Example:'''  <i><!--CODE-->"Easy" := right ("This is Easy",4);</i><!--ENDCODE-->
+
! Name !! Type !! Meaning
 +
|-
 +
| s || string || The string.
 +
|-
 +
| n || integer || How many characters to take from the end.
 +
|}
  
−
---~---~---~---~---~---~---~---~---
+
== Returns ==
−
<span id="bfright"></span>
+
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.
  
−
'''Function:'''  <i><!--CODE-->string right ( o : string, r : integer );</i><!--ENDCODE-->
+
== 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.
  
−
<!--TERM--> '''o'''
+
== Example ==
−
<!--DEFINITION-->        the original string to be parsed
+
<pre>
−
<!--TERM-->  '''r'''
+
dilbegin string say_verb(s : string);
−
<!--DEFINITION-->        The amount of characters to parse out
+
code
−
<!--TERM-->  '''return'''
+
{
−
<!--DEFINITION-->         the right portion of the string with length r
+
  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.
  
−
This function parses the string passed to it and returns the number of characters
+
== See also ==
−
from the right defined in its second argument.
+
* [[Manual:DIL Manual/left()|left()]]
−
'''Example:'''  <i><!--CODE-->"Easy" := right ("This is Easy",4);</i><!--ENDCODE-->
+
* [[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 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