Right (String function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (Full stop)
m (printtext and fix char -> pad in syntax terms)
Line 14: Line 14:
<td>The number of the right-most bytes to return. If the method object <var class="term">string</var> is shorter than the requested <var class="term">length</var>, it is either padded to the requested length or the entire method object <var class="term">string</var> is returned with no padding, depending on the value of the <var class="term">Pad</var> parameter.</td></tr>
<td>The number of the right-most bytes to return. If the method object <var class="term">string</var> is shorter than the requested <var class="term">length</var>, it is either padded to the requested length or the entire method object <var class="term">string</var> is returned with no padding, depending on the value of the <var class="term">Pad</var> parameter.</td></tr>
<tr><th>Pad</th>
<tr><th>Pad</th>
<td>This is an optional, but <var class="term">nameRequired</var>, parameter; used to pad the method object <var class="term">string</var>, on the left, if it is shorter than the requested <var class="term">length</var>. <i>char</i> defaults to a blank space. If set to the null string, no padding is applied.</td></tr>
<td>This is an optional, but <var class="term">nameRequired</var>, parameter; used to pad the method object <var class="term">string</var>, on the left, if it is shorter than the requested <var class="term">length</var>. <var class="term">pad</var> defaults to a single blank space. If set to the null string, no padding is applied.</td></tr>
</table>
</table>


==Usage notes==
==Usage notes==
<ul><li>The length must be a non-negative number. A negative number results in request cancellation.
<ul><li>The length must be a non-negative number. A negative number results in request cancellation.
<li>The pad parameter must be either null or a single character. A longer value results in request cancellation in <var class=product>Sirius Mods</var> version 7.2 and in a compilation error in <var class=product>Sirius Mods</var> 7.3 and higher.
<li>The pad parameter must be either null or a single character. A longer value results in request cancellation in <var class="product">"Sirius Mods"</var> Version 7.2 and in a compilation error in <var class="product">"Sirius Mods"</var> Version 7.3 and higher.
<li><var>Right</var> can be useful for right-justifying a value in a string, most typically by using a blank space as pad character.
<li><var>Right</var> can be useful for right-justifying a value in a string, most typically by using a blank space as pad character.
<li><var>Right</var> is available as of <var class="product">[[Sirius Mods]]</var> version 7.2.</ul>
<li><var>Right</var> is available as of <var class="product">[[Sirius Mods|"Sirius Mods"]]</var> version 7.2.</ul>


==Examples==
==Examples==
Line 29: Line 29:
The following request right-justifies the numbers 7, 123, and 99, and it left-justifies the number 88:
The following request right-justifies the numbers 7, 123, and 99, and it left-justifies the number 88:
<p class="code">begin
<p class="code">begin
   printText {7:right(5)}
   [[PrintText statement|printText]] {7:right(5)}
   printText {123:right(5)}
   printText {123:right(5)}
   printText {99:right(5)}
   printText {99:right(5)}
Line 37: Line 37:


==See also==
==See also==
<ul><li>For details of the <var>printtext</var> statement, please see <var>[[Intrinsic classes#printtext|printText]]</var>.</ul>
{{Template:String:Right footer}}
{{Template:String:Right footer}}

Revision as of 09:13, 23 February 2011

The right-most characters of the string (String class)


The Right intrinsic function returns the right-most characters of the method object string, possibly padding it on the left.

Syntax

%outString = string:Right( length, [Pad= c])

Syntax terms

%outString A variable to receive the string result of the Right method.
string The input, method object, string to which the method is applied.
length The number of the right-most bytes to return. If the method object string is shorter than the requested length, it is either padded to the requested length or the entire method object string is returned with no padding, depending on the value of the Pad parameter.
Pad This is an optional, but nameRequired, parameter; used to pad the method object string, on the left, if it is shorter than the requested length. pad defaults to a single blank space. If set to the null string, no padding is applied.

Usage notes

  • The length must be a non-negative number. A negative number results in request cancellation.
  • The pad parameter must be either null or a single character. A longer value results in request cancellation in "Sirius Mods" Version 7.2 and in a compilation error in "Sirius Mods" Version 7.3 and higher.
  • Right can be useful for right-justifying a value in a string, most typically by using a blank space as pad character.
  • Right is available as of "Sirius Mods" version 7.2.

Examples

  1. The following places the right-most 5 bytes of %x into %y. If %x is shorter than 6 bytes, then all of %x is copied into %y:

    %y = %x:right(5)

    The following request right-justifies the numbers 7, 123, and 99, and it left-justifies the number 88:

    begin printText {7:right(5)} printText {123:right(5)} printText {99:right(5)} printText {88:right(5, pad=)} end

See also