View comments | RSS feed
Contents > CFML Reference > ColdFusion Functions > Replace PreviousNext

Replace

Replaces occurrences of substring1 in a string with substring2, in a specified scope. The search is case-sensitive.

The string, after making replacements.

String functions

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

Find, REFind, ReplaceNoCase, ReplaceList, REReplace

Parameter

Description

string

A string or a variable that contains one. String in which to search

substring1

A string or a variable that contains one. String for which to search

substring2

String that replaces substring1

scope

  • one: replace the first occurrence (default)
  • all: replace all occurrences

To remove a string, specify the empty string ("") as substring2.

You do not need to escape comma characters in strings. For example, the following code deletes the commas from the sentence:

replace("The quick brown fox jumped over the lazy cow, dog, and cat.",",","","All")

<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>

Contents > CFML Reference > ColdFusion Functions > Replace PreviousNext

ColdFusion 9 | ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | Bug Reporting

Version 6.1

Comments are no longer accepted for ColdFusion MX 6.1. ColdFusion 8 is the current version.

Comments


Dylan_ said on Dec 28, 2004 at 11:36 AM :
I get an error when trying to replace the single quotation with the HTML equivilent:

<cfset this_record = Replace(this_record, chr(39), "&#39;", "ALL")>
-and-
<cfset this_record = Replace(this_record, "'", "&#39;", "ALL")>

..both break.
No screen name said on Jan 2, 2005 at 8:21 AM :
Hi,

I have the same problem.
What I want to do is change ; into ;"" ----> chr(59)chr(34)chr(34)
I don't know how to achieve this.

Is there somebody who can helkp me with this problem>

Bram
No screen name said on Mar 22, 2005 at 5:14 AM :
Have you tried escaping your hash i.e.

replaceNoCase(this_record, chr(39), "&##39;", "ALL")

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/coldfusion/6.1/htmldocs/functa68.htm