Right (String function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
 
(36 intermediate revisions by 5 users not shown)
Line 1: Line 1:
This [[Intrinsic classes|intrinsic]] function returns the right-most characters of the method object string,
{{Template:String:Right subtitle}}
possibly padding it on the left.                                                                           
                                                                                                           
Right is available as of version 7.2 of the [[Sirius Mods]].                                               
===Right syntax===                                                                                         
  %outStr = string:right(length [, pad=char])                                                             
===Syntax Terms===                                                                                         
<dl>                                                                                                       
<dt>%outStr                                                                                               
<dd>A variable to receive the string result of the Right method.                                           
<dt>string                                                                                                 
<dd>The string to which the method is applied.                                                             
<dt>length                                                                                                 
<dd>The number of the right-most bytes to return. If the method object is shorter than the requested bytes, 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.     
<dt>Pad=char                                                                                               
<dd>The character used to pad the method object string on the left if it is shorter than the requested length. ''char'' defaults to a blank. If set to null, no padding is applied.
                                                                                                           
Pad is a name-required parameter.                                                                         
                                                                                                           
</dl>                                                                                                     
===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]] 7.3 and higher.                                   
*The Right method can be useful for right-justifying a value in a string, most typically by using a blank as pad character.   
===Examples===                                                                                       
                                                                                                     
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                                                                                             
      [[Intrinsic classes#printtext|printText]] {7:right(5)}                                                 
      printText {123:right(5)}                                                                       
      printText {99:right(5)}                                                                        
      printText {88:right(5, pad='')}                                                                
    End


===See also===                                                                                       
The <var>Right</var> [[Intrinsic classes|intrinsic]] function returns the right-most characters of the method object string, possibly padding it on the left.
[[List of intrinsic String methods]]


[[Category:Intrinsic String methods|Right function]]
==Syntax==
[[Category:Intrinsic methods]]
{{Template:String:Right syntax}}
[[Category:System methods]]
===Syntax terms===
<table class="syntaxTable">
<tr><th>%outString</th>
<td>A variable to receive the string result of the <var>Right</var> method.</td></tr>
<tr><th>string</th>
<td>The input, method object, string to which the method is applied.</td></tr>
<tr><th>length</th>
<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>Pad</var> parameter.</td></tr>
<tr><th><var>Pad</var></th>
<td>An optional, [[Notation conventions for methods#Named parameters|name required]], 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>Pad</var> defaults to a single blank space. If set to the null string, no padding is performed.</td></tr>
</table>
 
==Usage notes==
<ul>
<li>The <var class="term">length</var> value must be a non-negative number. A negative number results in request cancellation.
<li>The <var>Pad</var> argument must be either the null string 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> is available as of <var class="product">Sirius Mods</var> version 7.2.
</ul>
 
==Examples==
The following places the right-most 5 bytes of <code>%x</code> into <code>%y</code>. If <code>%x</code> contains fewer than 6 bytes, then all of <code>%x</code> is copied into <code>%y</code>, padded on the left with blanks:
<p class="code">%y = %x:right(5)
</p>
The following request right-justifies the numbers 7, 123, and 99, and it left-justifies the number 88:
<p class="code">begin
  [[PrintText statement|printText]] {7:right(5)}
  printText {123:right(5)}
  printText {99:right(5)}
  printText {88:right(5, pad=&#39;')}
end
</p>
 
==See also==
{{Template:String:Right footer}}

Latest revision as of 22:00, 7 August 2012

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 An optional, name required, 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 performed.

Usage notes

  • The length value must be a non-negative number. A negative number results in request cancellation.
  • The Pad argument must be either the null string 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

The following places the right-most 5 bytes of %x into %y. If %x contains fewer than 6 bytes, then all of %x is copied into %y, padded on the left with blanks:

%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