Remove (String function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (1 revision)
m (1 revision)
Line 2: Line 2:


This [[Intrinsic classes|intrinsic]] function removes one or multiple occurrences of a specified substring
This [[Intrinsic classes|intrinsic]] function removes one or multiple occurrences of a specified substring
from an input string (the                                                                                
from an input string (the
method object), and it returns the modified version of the input string.                                
method object), and it returns the modified version of the input string.
                                                                                                         
 
The Remove function is available as of version 7.3 of the [[Sirius Mods]].                              
The Remove function is available as of version 7.3 of the [[Sirius Mods]].
==Syntax==
==Syntax==
{{Template:String:Remove syntax}}
{{Template:String:Remove syntax}}
Line 19: Line 19:
<td>An optional, name-required, argument that is the number of occurrences of ''substring'' to remove. Only values greater than 0 are valid.                                                                                                                                                                              If ''num'' is                                                          *less than the number of occurrences of the substring, only the first ''num'' 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.</td></tr>
<td>An optional, name-required, argument that is the number of occurrences of ''substring'' to remove. Only values greater than 0 are valid.                                                                                                                                                                              If ''num'' is                                                          *less than the number of occurrences of the substring, only the first ''num'' 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.</td></tr>
</table>
</table>
                                                                                                   
 
==Usage notes==
==Usage notes==
*The search for the target substring is context sensitive; case  matters in the attempt to find and remove the target characters.  
*The search for the target substring is context sensitive; case  matters in the attempt to find and remove the target characters.
*The Remove method is equivalent to calling the [[Replace (String function)|Replace]] method with an empty replacement string argument.
*The Remove method is equivalent to calling the [[Replace (String function)|Replace]] method with an empty replacement string argument.
==Examples==
==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.                              
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                                                                                  
     begin
     %x is longstring                                                                        
     %x is longstring
     %substr is string len 6                                                                
     %substr is string len 6
     %repl is string len 2                                                                  
     %repl is string len 2
     %out is longstring                                                                      
     %out is longstring
                                                                                           
 
     %x = 'Remove me'                                                                        
     %x = 'Remove me'
     %substr = ' me'                                                                        
     %substr = ' me'
     %out = %x:remove(%substr)                                                              
     %out = %x:remove(%substr)
     [[Intrinsic classes#printtext|printText]] {~} is {%out}                                        
     [[Intrinsic classes#printtext|printText]] {~} is {%out}
                                                                                           
 
     %substr = 'e'                                                                          
     %substr = 'e'
     %out = %x:remove(%substr, Count=2)                                                      
     %out = %x:remove(%substr, Count=2)
     printText {~} is {%out}                                                                
     printText {~} is {%out}
                                                                                           
 
The request output follows:                                                                
The request output follows:
     %out is Remove                                                                          
     %out is Remove
     %out is Rmov me
     %out is Rmov me


===See also===                                                                              
===See also===
[[List of intrinsic String methods]]
[[List of intrinsic String methods]]


[[Category:Intrinsic String methods|Remove function]]
[[Category:Intrinsic String methods|Remove function]]
[[Category:Intrinsic methods]]
[[Category:Intrinsic methods]]

Revision as of 14:04, 19 January 2011

Remove the occurrences of a specified substring (String class)


This 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 Remove function is available as of version 7.3 of the Sirius Mods.

Syntax

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

Syntax terms

%outStr A string variable to receive the modified input string.
string The 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, %outStr is set to a copy of string. If substring is null or longer than 256 characters, the request is cancelled.
Count=num An optional, name-required, argument that is the number of occurrences of substring to remove. Only values greater than 0 are valid. If num is *less than the number of occurrences of the substring, only the first num 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.
  • The Remove method is equivalent to calling the Replace method with an empty replacement string argument.

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}

The request output follows:

   %out is Remove
   %out is Rmov me

See also

List of intrinsic String methods