Remove (String function)

From m204wiki
Revision as of 05:02, 2 February 2011 by Goff (talk | contribs) (→‎Examples)
Jump to navigation Jump to search

Remove the occurrences of a specified substring (String class)


The Remove 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.

Syntax

%outString = string:Remove( substring, [Count= number])

Syntax terms

%outString A string variable to receive the modified input string.
string The input string to which the method is applied.
substring The substring that the method attempts to remove in the input 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 the 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