Left (String function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (1 revision)
m (1 revision)
Line 8: Line 8:
{{Template:String:Left syntax}}
{{Template:String:Left syntax}}
===Syntax terms===
===Syntax terms===
<dl>                                                                                                      
<table class="syntaxTable">
<dt>%outStr                                                                                                 
<tr><th>%outStr                                                                                                </th>
<dd>A variable to receive the string result of the Left method.                                             
<td>A variable to receive the string result of the Left method.                                            </td></tr>
<dt>string                                                                                                 
<tr><th>string                                                                                                </th>
<dd>The string to which the method is applied.                                                             
<td>The string to which the method is applied.                                                            </td></tr>
<dt>length                                                                                                 
<tr><th>length                                                                                                </th>
<dd>The number of the left-most bytes to return.                                                           
<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>
If the method object is shorter than the requested number of bytes, it is either                           
<tr><th>Pad=char                                                                                              </th>
padded to the requested length or the entire method object string is                                       
<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>
returned with no padding, depending on the value of the Pad parameter.                                     
</table>
<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==
==Usage notes==
*The ''length'' value must be a non-negative number. A negative number results in request cancellation.
*The ''length'' value must be a non-negative number. A negative number results in request cancellation.

Revision as of 05:39, 19 January 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.

Left is available as of version 7.2 of the Sirius Mods.

Syntax

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

Syntax terms

%outStr A variable to receive the string result of the Left method.
string The 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=char 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.

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.

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':

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

See also

List of intrinsic String methods