Replace

Description

Returns string with occurrences of substring1 replaced with substring2 in a specified scope.

Category

String functions

Syntax

Replace(string, substring1, substring2 [, scope ]) 

See also

REFind, ReplaceNoCase, ReplaceList, REReplace

Parameters

Parameter
Description
string
A string
substring1
String to replace
substring2
String that replaces occurrences of substring1
scope
Defines how to complete the replace operation:
  • ONE    Replace only the first occurrence (default)
  • ALL    Replace all occurrences
Defines how to complete the replace operation:

Example

<!--- This example shows the use of Replace --->
<html>
<head>
<title>
Replace Example
</title>
</head>
<body bgcolor = silver>
<H3>Replace Example</H3>

<P>The Replace function returns <I>string</I> with <I>substring1</I> 
replaced by <I>substring2</I> in the specified scope. This is a 
case-sensitive search.

<cfif IsDefined("FORM.MyString")>
<P>Your original string, <cfoutput>#FORM.MyString#</cfoutput>
<P>You wanted to replace the substring <cfoutput>#FORM.MySubstring1#
 </cfoutput>
with the substring <cfoutput>#FORM.MySubstring2#</cfoutput>.
<P>The result: <cfoutput>#Replace(FORM.myString,
FORM.MySubstring1, FORM.mySubString2)#</cfoutput>
</cfif>
...