Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

UDF Help

New Here ,
May 25, 2007 May 25, 2007
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??
346
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 25, 2007 May 25, 2007
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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
May 25, 2007 May 25, 2007
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, , ,&gt;, &lt;, '';
return ReplaceList(theString, remove_char_list, replace_char_list);
}
</cfscript>
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
May 25, 2007 May 25, 2007
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")>
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 25, 2007 May 25, 2007
LATEST
What is your actual requirement here? ie: what is the issue you're trying
to resolve in writing this UDF?

--
Adam
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources