ReplaceNoCase

Description

Replaces occurrences of substring1 with substring2, in the specified scope. The search is case-insensitive.

Returns

A copy of the string, after making replacements.

Category

String functions

Function syntax

ReplaceNoCase(string, substring, callback, [ scope ])

See also

FindREFindReplaceReplaceListREReplace

History

ColdFusion (2021 release): Added the parameter start.

ColdFusion (2016 release): Introduced named parameters.

Parameters

Parameter

Description

string

A string (or variable that contains one) within which to replace substring.

substring

String (or variable that contains one) to replace, if found.

callback

Function to replace string. Parameters are:

  • transform
  • position
  • original

scope

  • one: replaces the first occurrence (default).
  • all: replaces all occurrences.

start

Position to start searching in the string (starts at 1).

Example

<cfscript>
    myStr="hAppy app application apply appreciate appreciation Apprentice";
    outStr = replacenocase( myStr, "app", function (transform, position, original) { return UCase(transform); }
, "all");
    writeoutput("Output:" & outStr);
</cfscript>

Example 2

<cfscript> 
  // ReplaceNoCase( String string, String substring, Object replacement, String scope, int start ) 
  string="The quick brown fox jumped over the lazy cow." 
  substring="ow" 
  replacement="aze" 
  scope="ALL" 
  start=len("The quick brown") 
  myoutput=replacenocase(string,substring,replacement, scope, start) 
  writeOutput(myoutput & "<br/>") 
  // scope="ONE" 
  myoutput1=replacenocase(string,substring,replacement, "ONE", start) 
  writeOutput(myoutput1 & "<br/>") 
</cfscript>

Output

The quick brown fox jumped over the lazy caze.
The quick brown fox jumped over the lazy caze.

Example 3

<cfscript> 
  // Define the callback function 
  callback=(regexp,position,original)=>{ 
    retString = regExp.reverse()&"aze" 
    return retString 
  } 
  baseStr="The quick brown fox jumped over the lazy cow." 
  writeOutput(replaceNoCase(baseStr, "ow", callback, "all", len("The quick bro"))  & "<br>") 
  writeOutput(replaceNoCase(baseStr, "ow", callback, "all", len("The quick brown"))  & "<br>") 
</cfscript> 

Output

The quick brWOazen fox jumped over the lazy cWOaze.
The quick brown fox jumped over the lazy cWOaze.

 Adobe

Recevez de l’aide plus rapidement et plus facilement

Nouvel utilisateur ?

Adobe MAX 2024

Adobe MAX
La conférence sur la créativité

Du 14 au 16 octobre à Miami Beach et en ligne

Adobe MAX

La conférence sur la créativité

Du 14 au 16 octobre à Miami Beach et en ligne

Adobe MAX 2024

Adobe MAX
La conférence sur la créativité

Du 14 au 16 octobre à Miami Beach et en ligne

Adobe MAX

La conférence sur la créativité

Du 14 au 16 octobre à Miami Beach et en ligne