Left (String function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
mNo edit summary
m (misc formatting)
 
(37 intermediate revisions by 5 users not shown)
Line 1: Line 1:
This [[Intrinsic classes|intrinsic]] function returns the left-most characters of the method object string,
{{Template:String:Left subtitle}}
possibly padding it on the right.                                                                         
                                                                                                         
Left is available as of version 7.2 of the [[Sirius Mods]].                                               
===Left syntax=== 
  %outStr = string:left(length, [Pad=char])
====Syntax Terms==== 
<dl>                                                                                                     
<dt>%outStr                                                                                               
<dd>A variable to receive the string result of the Left method.                                           
<dt>string                                                                                               
<dd>The string to which the method is applied.                                                           
<dt>length                                                                                               
<dd>The number of the left-most bytes to return.                                                         
If the method object is shorter than the requested number of 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 right 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'' value must be a non-negative number. A negative number results in request cancellation.
*The pad parameter value 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 Left method is identical to the [[Substring (String function)|Substring]] method with a 1 for the first argument.
===Examples===                                                                       
                                                                                     
The following statement places the left-most 5 bytes of %x into %y.
If %x is shorter than 6 bytes, then all of %x is copied into %y:                      
    %y = %x:left(5)                                                                   
                                                                                     
The following statement displays ''''Wheeeee'''':                                     
    [[Intrinsic classes#printtext|printText]] {'Wh':left(7, pad='e')}


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


[[Category:Intrinsic String methods|Left function]]
==Syntax==
[[Category:Intrinsic methods]]
{{Template:String:Left syntax}}
[[Category:System methods]]
 
===Syntax terms===
<table>
<tr><th>%outString</th>
<td>A variable to receive the string result of the <var>Left</var> method.</td></tr>
 
<tr><th>string</th>
<td>The input, method object <var class="term">string</var> to which the method is applied.</td></tr>
 
<tr><th>length</th>
<td>The number of the left-most bytes to return.  If the method object is shorter than the requested number of 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 <var>Pad</var> parameter.</td></tr>
 
<tr><th><var>Pad</var></th>
<td>This optional, [[Notation conventions for methods#Named parameters|name required]], parameter is the character used to pad the method object string on the right if it is shorter than the requested length. <var class="term">c</var> defaults to a blank. If set to null, no padding is applied.
</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>
 
<li>The <var>Pad</var> parameter value must be either null or a single character. A longer value results in a compilation error. </li>
 
<li><var>Left</var> is identical to the <var>[[Substring (String function)|Substring]]</var> method with <code>1</code> as its first argument. </li>
</ul>
 
==Examples==
<ol>
<li>The following statement places the left-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 right with blanks:
<p class="code">%y = %x:left(5)
</p>
<li>The following statement displays <code>Wheeeee</code>:
<p class="code">[[PrintText statement|printText]] {'Wh':left(7, pad='e')}
</p></ol>
 
==See also==
<ul>
<li><var>[[UnicodeLeft (Unicode function)|UnicodeLeft]]</var> </li>
<li><var>[[Right (String function)|Right]]</var> and <var>[[UnicodeRight (Unicode function)|UnicodeRight]]</var> </li>
<li><var>[[Center (String function)|Center]]</var> </li>
</ul>
{{Template:String:Left footer}}

Latest revision as of 18:08, 11 July 2017

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


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

Syntax

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

Syntax terms

%outString A variable to receive the string result of the Left method.
string The input, method object string to which the method is applied.
length The number of the left-most bytes to return. If the method object is shorter than the requested number of 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.
Pad This optional, name required, parameter is the character used to pad the method object string on the right if it is shorter than the requested length. c defaults to a blank. If set to null, no padding is applied.

Usage notes

  • The length value must be a non-negative number. A negative number results in request cancellation.
  • The Pad parameter value must be either null or a single character. A longer value results in a compilation error.
  • Left is identical to the Substring method with 1 as its first argument.

Examples

  1. The following statement places the left-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 right with blanks:

    %y = %x:left(5)

  2. The following statement displays Wheeeee:

    printText {'Wh':left(7, pad='e')}

See also