Replace

Replaces occurrences of substring1 in a string with obj, in a specified scope.

The search is case-sensitive. Function returns original string with replacements made

Method Signature

Replace(string=[string], substring1=[string], obj=[any], scope=[string])

Arguments

Argument
Type
Required
Description
Default

string

string

true

The string to search

substring1

string

true

The substring to search for

obj

any

true

The string to replace substring1 with

scope

string

true

The scope to search in

one

Examples

Replace uppercase 'U' with lowercase 'u'

Replace in Script Syntax

Run Example

getVal = replace( "Boxlang", "U", "u" );
writeDump( getVal );

Result: Boxlang

Replace uppercase 'O' with lowercase 'o', but only once

Something similar in Tag Syntax

Run Example

Result: Boxlang

Example using Callback Function

You can pass in a callback function to the third argument of the replace function

Run Example

Result: A mAN a plAN a cANal.

Example with start argument (Replace lowercase 'o' with uppercase 'O' from the third position)

You can pass position to start searching in the string

Run Example

Result: Love Boxlang

Additional Examples

Last updated

Was this helpful?