Template Engine language reference > Template Engine utilities > String functions > $string.replace

$string.replace
This function takes an input string, a regular expression and a replacement string as input. All sub-strings in the input string that match the regular expression are replaced by the replacement string in the output returned by this function. Note that it is the output string returned from this function that is manipulated, and that no input strings are modified.
Syntax
$string.replace(<inStr>, <regex>, <repStr>)
inStr
regex
repStr
For example, if you in your template reference a Composition Center text resource, then this resource will by default include a <p> and </p> tag (<p>Some text</p>). If you want to remove the <p> and </p> tags you can apply $string.replace to the text and use an empty string as replacement string:
#set($text=$docdef.section1.text1)
$string.replace($text.toString(), '<p>|</p>', '')
Note:
The text resource is of the type docdefResource. You must use the function toString() to convert the resource to a string ($text.toString() in example above).
Template examples
Example 110
Template
#set($text='<p>Hello world!</p>')
$string.replace($text, '<p>|</p>', '')
Output
Hello world!
 
Example 111
Template
#set($text=$docdef.section1.text1)
Original text: $text
Manipulated text: $string.replace($text.toString(), '</?p>', '')
Output
Original text: <p>Hello world!</p>
Manipulated text: Hello world!
 
Example 112
Template
#set($a='Hello Mr "Nice Guy"')
$string.replace($a, '\N{QUOTATION MARK}', '''')
Output
Hello Mr 'Nice Guy'
 
Example 113
Template
#set($a='Hello
how
are
you?')
$string.replace($a, '\n', ' ')
Output
Hello how are you?
 
OpenText StreamServe 5.6.2 Updated: 2018-01-26