RPTools

Personal tools
From MapToolDoc

replace

replace() Function

Introduced in version 1.3b48

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. This means if the pattern string contains any regular expression special characters they must be escaped.

Usage

  1. replace(str, pattern, value)
  1. replace(str, pattern, value, times)

Example

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

Returns

   This-is-a-test
   This-is-a test
  1.     [r: tString = "is (a) t"]
  2.     [r: replace("This is (a) test", "\\Q" + tString + "\\E", "-")]

Returns (This is useful for search+replace of any string you feed to replace() that might have regex codes in it like parenthesis)

   This-est