Replace()

Top  Previous  Next

Replace() - Replace a substring within a string

Description

The Replace() function is used to replace a specified substring with an alternate substring within a string.

Replace(haystack, needle, replacement[, start[, count[, compare]]])

Parameters
The haystack parameter is the string to be searched.

The needle parameter is the string to search for.

The replacement parameter is the string to replace the needle parameter with.

The optional start parameter specifies the position to start the search.

The optional count parameter specifies the number of substitutions to perform. The default is all possible substitutions.

The optional compare parameter specifies the the method of comparison according to [id=43]this table[/id]. The start parameter is required if compare is specified.

Example

haystack = "The quick brown fox"

 

'returns 'The quick orange fox'

Result = Replace(haystack, "brown", "orange")