Thursday, April 21, 2005

Coldfusion Replace Question

Question: I am getting an error when I do this: <cfset newfilename = Replace(sourcefilename, " ", "_", [ALL])>

Because I am specifying the scope of the replace. I want it to do it for every occurence as opposed to one.

The error I get is: Missing argument name. When using named parameters to a function, every parameter must have a name Is there a better way to do this?

Answer:
<cfset newfilename = Replace(sourcefilename, " ", "_", "ALL")> The "ALL" is supposed to be in quotes. So your statement would be:

<cfset newfilename = Replace(sourcefilename, " ", "_", "ALL")> In the documentation, [] usually means "optional". So, you could have the statement:

<cfset newfilename = Replace(sourcefilename, " ", "_")>
<!--- without the "ALL", replace only first occurrence (default) --->
<cfset newfilename = Replace(sourcefilename, " ", "_", "ONE")>
<!--- replace only first occurrence --->

Or your statement with the "ALL".

<cfset newfilename = Replace(sourcefilename, " ", "_", "ALL")>

0 Comments:

Post a Comment

<< Home