0
UDF Help
New Here
,
/t5/coldfusion-discussions/udf-help/td-p/527432
May 25, 2007
May 25, 2007
Copy link to clipboard
Copied
I am trying to write a UDF for replacing some characters from
my string. I am using replace list but somehow its just replacing
only first character but not the others in the list
Here is what I am trying to do
<cfscript>
function Rep(theString){
var remove_char_list = "&, |, \, >, <, :";
var replace_char_list = "and, ' ''';
return ReplaceList(theString, remove_char_list, replace_char_list);
}
</cfscript>
basically & to be removed and (XML), and all other with empty strings, with this it just replace all occurences of & whereas others are not being replaced
Any comments??
Here is what I am trying to do
<cfscript>
function Rep(theString){
var remove_char_list = "&, |, \, >, <, :";
var replace_char_list = "and, ' ''';
return ReplaceList(theString, remove_char_list, replace_char_list);
}
</cfscript>
basically & to be removed and (XML), and all other with empty strings, with this it just replace all occurences of & whereas others are not being replaced
Any comments??
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
RonFusion
AUTHOR
New Here
,
/t5/coldfusion-discussions/udf-help/m-p/527433#M48219
May 25, 2007
May 25, 2007
Copy link to clipboard
Copied
My main intent is to get rid of all the replaces that I was
using before and just ReplaceList because most of the characters
are to be replaced with empty string and only & with and
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Advocate
,
/t5/coldfusion-discussions/udf-help/m-p/527434#M48220
May 25, 2007
May 25, 2007
Copy link to clipboard
Copied
Don't you need to have an equal number of elements in your
remove and replace lists?
e.g.:
<cfscript>
function Rep(theString){
var remove_char_list = "&, |, \, >, <, :";
var replace_char_list = "and, , ,>, <, '';
return ReplaceList(theString, remove_char_list, replace_char_list);
}
</cfscript>
e.g.:
<cfscript>
function Rep(theString){
var remove_char_list = "&, |, \, >, <, :";
var replace_char_list = "and, , ,>, <, '';
return ReplaceList(theString, remove_char_list, replace_char_list);
}
</cfscript>
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Advocate
,
/t5/coldfusion-discussions/udf-help/m-p/527435#M48221
May 25, 2007
May 25, 2007
Copy link to clipboard
Copied
Now that I've read your reply, it seems like a better match
would be to do 2 replaces - 1st replace swaps out the ampersand
(&), 2nd replace uses regular expressions to remove everything
else
<cfset sMyString = Replace(sMyString, "&", "and", "all")>
<cfset sMyString = ReReplace(sMyString , "[<>'""/]", "", "all")>
<cfset sMyString = Replace(sMyString, "&", "and", "all")>
<cfset sMyString = ReReplace(sMyString , "[<>'""/]", "", "all")>
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
LEGEND
,
LATEST
/t5/coldfusion-discussions/udf-help/m-p/527436#M48222
May 25, 2007
May 25, 2007
Copy link to clipboard
Copied
What is your actual requirement here? ie: what is the issue
you're trying
to resolve in writing this UDF?
--
Adam
to resolve in writing this UDF?
--
Adam
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

