Left (String function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (1 revision)
m (re-match syntax diagram to revised template; fix tags.)
Line 1: Line 1:
{{Template:String:Left subtitle}}
{{Template:String:Left subtitle}}


This [[Intrinsic classes|intrinsic]] function returns the left-most characters of the method object string,
This [[Intrinsic classes|intrinsic]] function returns the left-most characters of the method object string, possibly padding it on the right.
possibly padding it on the right.


<var>Left</var> is available as of version 7.2 of the <var class=product>Sirius Mods</var>.
==Syntax==
==Syntax==
{{Template:String:Left syntax}}
{{Template:String:Left syntax}}
Line 10: Line 8:
<table class="syntaxTable">
<table class="syntaxTable">
<tr><th>%outStr</th>
<tr><th>%outStr</th>
<td>A variable to receive the string result of the <var>Left</var> method.                                           </td></tr>
<td>A variable to receive the string result of the <var>Left</var> method.</td></tr>
<tr><th>string</th>
<tr><th>string</th>
<td>The string to which the method is applied.                                                             </td></tr>
<td>The input, method object <var class="term">string</var> to which the method is applied.</td></tr>
<tr><th>length</th>
<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 Pad parameter.                                     </td></tr>
<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 class="term">Pad</var> parameter.</td></tr>
<tr><th>Pad=char</th>
<tr><th>Pad</th>
<td>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.</td></tr>
<td>This is an optional, but <var class="term">nameRequired</var>, parameter and is the character used to pad the method object string on the right if it is shorter than the requested length. <i>char</i> defaults to a blank. If set to null, no padding is applied.
</table>
</table>


==Usage notes==
==Usage notes==
*The ''length'' value must be a non-negative number. A negative number results in request cancellation.
<ul><li>The <var class="term">length</var> 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 <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 <var class="term">pad</var> parameter value 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.
*The <var>Left</var> method is identical to the [[Substring (String function)|Substring]] method with a 1 for the first argument.
<li>The <var>Left</var> method is identical to the [[Substring (String function)|Substring]] method with a 1 for the first argument.
</li><var>Left</var> is available as of <var class="product">Sirius Mods</var> version 7.2.</ul>
 
==Examples==
==Examples==
 
<ol><li>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:
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:
<p class="code">%y = %x:left(5)
<p class="code">%y = %x:left(5)
</p>
</p>
The following statement displays ''''Wheeeee'''':
<li>The following statement displays ''''Wheeeee'''':
<p class="code">[[Intrinsic classes#printtext|printText]] {'Wh':left(7, pad='e')}
<p class="code">printText {'Wh':left(7, pad='e')}
</p></ol>


</p>
==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:Left footer}}
{{Template:String:Left footer}}

Revision as of 03:40, 2 February 2011

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


This 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

%outStr 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 is an optional, but nameRequired, parameter and is 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.

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 method with a 1 for the first argument.
  • Left is available as of Sirius Mods version 7.2.

Examples

  1. 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)

  2. The following statement displays 'Wheeeee':

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

See also

  • For details of the printtext statement, please see printText