String.replace(find, replace) Last updated: 13. Nov 2023

Replaces specified text in a specific string with another text.

Parameters

Name Type Description
find string String to search for within the specified text.
replace string Text to replace with.

Returns

Replaced text in string. Does not change the initial string.

Example

Code example (#JS)

#JS is mixed HTML (or other text file) with inline JavaScript with # starting and ending each inline statement.
#{
    var text = "hello world";

    /* Replaces "hello" with "thank you" */
    text = docly.replace(text, "hello", "thank you");
    write(text);
}#

Output

The #JS code above produces the output shown below:
thank you world