Remove (String function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (re-match syntax diagram to revised template; more tags.)
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 an input string (the method object), and it returns the modified version of the input string.
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.


==Syntax==
==Syntax==
Line 8: Line 8:
<table class="syntaxTable">
<table class="syntaxTable">
<tr><th>%outString</th>
<tr><th>%outString</th>
<td>A string variable to receive the modified input <var class="term">string</var>.</td></tr>
<td>A string variable to receive the modified method object (input) <var class="term">string</var>.</td></tr>
<tr><th>string</th>
<tr><th>string</th>
<td>The input <var class="term">string</var> to which the method is applied.</td></tr>
<td>The method object (ie: input) <var class="term">string</var> to which the method is applied.</td></tr>
<tr><th>substring</th>
<tr><th>substring</th>
<td>The substring that the method attempts to remove in the input string. 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>
<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</th>
<tr><th>Count</th>
<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 substring, all occurrences of the given substring are removed.<li><b><i>not specified</i></b>, all occurrences are removed.</ul></td></tr>
<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 substring is context sensitive; case  matters in the attempt to find and remove the target characters.
<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 the [[Replace (String function)|Replace]] method with an empty replacement string argument.
<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</var> version 7.3.</ul>
<li><var>Remove</var> is available as of <var class="product">[[Sirius Mods]]</var> Version 7.3.</ul>


==Examples==
==Examples==
<ol><li>
<ol><li>
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 substring.
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
<p class="code">begin
   %x is longstring
   %x is longstring
Line 47: Line 47:


==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:Remove footer}}
{{Template:String:Remove footer}}

Revision as of 00:41, 3 February 2011

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 (ie: 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:
  • less than the number of occurrences of the subString, only the first number occurrences are removed.
  • greater than or equal to the number of occurrences of the subString, all occurrences of the given subString are removed.
  • not specified, all occurrences are removed.

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

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

See also

  • For details of the printtext statement, please see printText