TrimLeft and TrimRight (String functions): Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
mNo edit summary |
||
Line 7: | Line 7: | ||
===Syntax terms=== | ===Syntax terms=== | ||
<table class="syntaxTable"> | <table class="syntaxTable"> | ||
<tr><th>%outString</th><td>Is the string that results from removing <var class="term">amount</var> bytes from the left or right of | <tr><th>%outString</th><td>Is the string that results from removing <var class="term">amount</var> bytes from the left or right of <var class="term">string</var>.</td></tr> | ||
<tr><th>string</th> | <tr><th>string</th> | ||
<td>The method string object from which bytes are removed.</td></tr> | <td>The method string object from which bytes are removed.</td></tr> | ||
<tr><th>amount</th> | <tr><th>amount</th> | ||
<td>The number of bytes to remove from the left or right of | <td>The number of bytes to remove from the left or right of <var class="term">string</var>.</td></tr> | ||
</table> | </table> | ||
==Usage notes== | ==Usage notes== |
Revision as of 13:27, 5 February 2011
Trim bytes from left or right of string (String class)
[Introduced in Sirius Mods 7.9]
These methods remove a specified number of bytes from the left or right end of a string.
Syntax
%outString = string:TrimLeft( amount)
%outString = string:TrimRight( amount)
Syntax terms
%outString | Is the string that results from removing amount bytes from the left or right of string. |
---|---|
string | The method string object from which bytes are removed. |
amount | The number of bytes to remove from the left or right of string. |
Usage notes
- An amount of 0 results in the output string being set equal to the method string object.
- A negative amount or an amount greater than 231 results in request cancellation.
- An amount greater than or equal to the length of the method string object results in the output string being set to a null string.
- TrimLeft accomplishes the same thing as SubString when used with just the starting position and without a length. While it might be a little bit more efficient than SubString, it's mainly available for completeness.
- TrimRight functionality can be achieved by using the Left and Length functions but it is considerably more efficient and convenient.
Examples
The following
begin %ls is longstring %ls = 'Life is good':trimRight(1) printtext {~} = '{%ls}' %ls = 'Life is good':trimLeft(3) printtext {~} = '{%ls}' end
outputs
%ls = 'Life is goo' %ls = 'e is good'