TrimLeft and TrimRight (String functions): Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
No edit summary |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
{{Template:String:TrimLeft and TrimRight subtitle}} | {{Template:String:TrimLeft and TrimRight subtitle}} | ||
These methods remove a specified number of bytes from the left or right end of a string. | These methods remove a specified number of bytes from the left or right end of a string. | ||
==Syntax== | ==Syntax== | ||
Line 13: | Line 12: | ||
<td>The number of bytes to remove from the left or right of <var class="term">string</var>.</td></tr> | <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== | ||
<ul> | <ul> | ||
<li>An <var class="term">amount</var> of 0 results in the output string being set equal to the | <li>An <var class="term">amount</var> of 0 results in the output string being set equal to the value of <var class="term">string</var>. | ||
<li>A negative <var class="term">amount</var> or an <var class="term">amount</var> greater than 2<sup>31</sup> results in request cancellation. | <li>A negative <var class="term">amount</var> or an <var class="term">amount</var> greater than 2<sup>31</sup> results in request cancellation. | ||
<li>An <var class="term">amount</var> greater than or equal to the length of | <li>An <var class="term">amount</var> greater than or equal to the length of <var class="term">string</var> results in the output string being set to a null string. | ||
<li><var>TrimLeft</var> accomplishes the same thing as <var>[[Substring (String function)|SubString]]</var> when used with just the starting position and without a length. While it might be a little bit more efficient than <var>SubString</var>, it's mainly available for completeness. | <li><var>TrimLeft</var> accomplishes the same thing as <var>[[Substring (String function)|SubString]]</var> when used with just the starting position and without a length. While it might be a little bit more efficient than <var>SubString</var>, it's mainly available for completeness. | ||
<li><var>TrimRight</var> functionality can be achieved by using the <var>[[Left (String function)|Left]]</var> and <var>[[ | <li><var>TrimRight</var> functionality can be achieved by using the <var>[[Left (String function)|Left]]</var> and <var>[[Length (String function)|Length]]</var> functions but it is considerably more efficient and convenient than doing so. | ||
</ul> | </ul> | ||
==Examples== | ==Examples== | ||
The following | The following code: | ||
<p class="code">begin | <p class="code">begin | ||
%ls is longstring | %ls is longstring | ||
%ls = 'Life is good':trimRight(1) | %ls = 'Life is good':trimRight(1) | ||
[[PrintText statement|printText]] {~} = '{%ls}' | |||
%ls = 'Life is good':trimLeft(3) | %ls = 'Life is good':trimLeft(3) | ||
printtext {~} = '{%ls}' | printtext {~} = '{%ls}' | ||
end | end | ||
</p> | </p> | ||
outputs | outputs: | ||
<p class="output">%ls = 'Life is goo' | <p class="output">%ls = 'Life is goo' | ||
%ls = 'e is good' | %ls = 'e is good' | ||
</p> | </p> | ||
==See also== | ==See also== | ||
{{Template:String:TrimLeft footer}} | {{Template:String:TrimLeft footer}} |
Latest revision as of 22:38, 3 September 2015
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 value of string.
- A negative amount or an amount greater than 231 results in request cancellation.
- An amount greater than or equal to the length of string 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 than doing so.
Examples
The following code:
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'