Remove (String function): Difference between revisions
m (1 revision) |
m (→Examples) |
||
(20 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
{{Template:String:Remove subtitle}} | {{Template:String:Remove subtitle}} | ||
The <var>Remove</var> [[Intrinsic classes|intrinsic]] function removes one or multiple occurrences of a specified substring from the method object (input) string, returning the modified version. | |||
from | |||
method object), | |||
==Syntax== | ==Syntax== | ||
{{Template:String:Remove syntax}} | {{Template:String:Remove syntax}} | ||
===Syntax terms=== | ===Syntax terms=== | ||
<table class="syntaxTable"> | <table class="syntaxTable"> | ||
<tr><th>% | <tr><th>%outString</th> | ||
<td>A string variable to receive the modified input string. | <td>A string variable to receive the modified method object (input) <var class="term">string</var>.</td></tr> | ||
<tr><th>string | <tr><th>string</th> | ||
<td>The string to which the method is applied. | <td>The method object (that is, input) <var class="term">string</var> to which the method is applied.</td></tr> | ||
<tr><th>substring | <tr><th>substring</th> | ||
<td>The substring that the method attempts to remove in the | <td>The substring that the method attempts to remove in the method object <var class="term">string</var>. If <var class="term">string</var> contains no occurrences of <var class="term">substring</var>, <var class="term">%outString</var> is set to a copy of <var class="term">string</var>. If <var class="term">substring</var> is null or longer than 256 characters, the request is cancelled.</td></tr> | ||
<tr><th>Count | <tr><th><var>Count</var></th> | ||
<td>An optional, name-required, argument that is the number of occurrences of | <td>An optional, name-required, argument that is the number of occurrences of <var class="term">substring</var> to remove. Only values greater than 0 are valid. If <i>number</i> is:<ul><li><b><i>less</i></b> than the number of occurrences of the <var class="term">substring</var>, only the first <i>number</i> occurrences are removed.<li><b><i>greater</i></b> than or <b><i>equal to</i></b> the number of occurrences of the <var class="term">substring</var>, all occurrences of the given <var class="term">substring</var> are removed.<li><b><i>not specified</i></b>, all occurrences are removed.</ul></td></tr> | ||
</table> | </table> | ||
==Usage notes== | ==Usage notes== | ||
<ul><li>The search for the target <var class="term">substring</var> is context sensitive; case <b><i>matters</i></b> in the attempt to find and remove the target characters. | |||
<li><var>Remove</var> is equivalent to calling <var>[[Replace (String function)|Replace]]</var> method with an empty replacement string argument. | |||
<li><var>Remove</var> is available as of <var class="product">[[Sirius Mods|Sirius Mods]]</var> Version 7.3.</ul> | |||
==Examples== | ==Examples== | ||
The following request shows two examples of <var>Remove</var> calls against the same input string: the first call removes an occurrence of a specified <var class="term">substring</var>; the second removes both occurrences of a different <var class="term">substring</var>. | |||
<p class="code">begin | |||
%x is longstring | |||
%substr is string len 6 | |||
%repl is string len 2 | |||
%out is longstring | |||
%x = 'Remove me' | |||
%substr = ' me' | |||
%out = %x:remove(%substr) | |||
[[PrintText statement|printText]] {~} is {%out} | |||
%substr = 'e' | |||
%out = %x:remove(%substr, Count=2) | |||
printText {~} is {%out} | |||
end | |||
</p> | |||
The request output follows: | The request output follows: | ||
<p class="output">%out is Remove | |||
%out is Rmov me | |||
</p> | |||
==See also== | ==See also== | ||
{{Template:String:Remove footer}} | |||
Latest revision as of 21:02, 5 November 2012
Remove the occurrences of a specified substring (String class)
The Remove intrinsic function removes one or multiple occurrences of a specified substring from the method object (input) string, returning the modified version.
Syntax
%outString = string:Remove( substring, [Count= number])
Syntax terms
%outString | A string variable to receive the modified method object (input) string. |
---|---|
string | The method object (that is, input) string to which the method is applied. |
substring | The substring that the method attempts to remove in the method object string. If string contains no occurrences of substring, %outString is set to a copy of string. If substring is null or longer than 256 characters, the request is cancelled. |
Count | An optional, name-required, argument that is the number of occurrences of substring to remove. Only values greater than 0 are valid. If number is:
|
Usage notes
- The search for the target substring is context sensitive; case matters in the attempt to find and remove the target characters.
- Remove is equivalent to calling Replace method with an empty replacement string argument.
- Remove is available as of Sirius Mods Version 7.3.
Examples
The following request shows two examples of Remove calls against the same input string: the first call removes an occurrence of a specified substring; the second removes both occurrences of a different substring.
begin %x is longstring %substr is string len 6 %repl is string len 2 %out is longstring %x = 'Remove me' %substr = ' me' %out = %x:remove(%substr) printText {~} is {%out} %substr = 'e' %out = %x:remove(%substr, Count=2) printText {~} is {%out} end
The request output follows:
%out is Remove %out is Rmov me