replace: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
(New page: ==Function replace== Returns the string with the occurrences of a pattern replaced by the specified value. If the number of times to perform the replacement is not specified then all occu...)
 
m (Applied Template:MacroFunction)
Line 1: Line 1:
==Function replace==
{{MacroFunction
 
|name=replace
|description=
Returns the string with the occurrences of a pattern replaced by the specified value. If the number of times to perform the replacement is not specified then all occurrences of the pattern are replaced. Pattern can be a [[Macros:regular expression|regular expression]].
Returns the string with the occurrences of a pattern replaced by the specified value. If the number of times to perform the replacement is not specified then all occurrences of the pattern are replaced. Pattern can be a [[Macros:regular expression|regular expression]].


===Usage===
|usage=
<source lang="mtmacro" line>
<source lang="mtmacro" line>
[h: newStr = replace(str, pattern, value)]
[h: newStr = replace(str, pattern, value)]
Line 9: Line 10:
</source>
</source>


 
|example=
 
===Examples===
<source lang="mtmacro" line>
<source lang="mtmacro" line>
     [r: replace("This is a test", " ", "-")]
     [r: replace("This is a test", " ", "-")]
Line 19: Line 18:
     This-is-a-test
     This-is-a-test
     This-is-a test
     This-is-a test
}}
[[Category:String Function]]

Revision as of 03:21, 9 March 2009

replace() Function

Returns the string with the occurrences of a pattern replaced by the specified value. If the number of times to perform the replacement is not specified then all occurrences of the pattern are replaced. Pattern can be a regular expression.

Usage

[h: newStr = replace(str, pattern, value)]
[h: newStr = replace(str, pattern, value, times)]

Example

    [r: replace("This is a test", " ", "-")]
    [r: replace("This is a test", " ", "-", 2)]

Returns

   This-is-a-test
This-is-a test