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

Beginners UDFs

Participant ,
Jun 06, 2008 Jun 06, 2008
Hi all,
What do you think of this udf? How can I make it better have I done it ok? Thanks for any input
TOPICS
Getting started
319
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 ,
Jun 06, 2008 Jun 06, 2008
To make it better:

1. use a cffunction tag. In this specific case it might not make much difference, but it's a good habit to adopt as the cfargument tag is pretty useful.

2. This is wrong
var xvali = ReReplace(info,"<P>","<p>","all");
because there is no variable in your function called info.

3. Your function would be easier to maintain (add more substutions) if you start with two lists and do a loop.

something like this

var mystring = arguments.texttoxhtml;
var goodlist = "<p>,</p>,<b>,</b>";
var badlist = "<P>,</P>,<STRONG>,</STRONG>";
var i = 1;
var listitems = ListLen(GoodList);
for (i = 1; i lte ListItems; i = i + 1) {
MyString = Replace(MyString, ListGetAt(BadList, i), ListGetAt(GoodList, i), "all");
}
</cfscript>
<cfreturn MyString>
}

That's the general idea. If I got anything wrong, you can fix it.
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
Participant ,
Jun 09, 2008 Jun 09, 2008
LATEST
Thak you Dan I did as you said and it works great, that for cfscript loop is guaranteed to give me a headache!

for (i = 1; i lte ListItems; i = i + 1) {
MyString = Replace(MyString, ListGetAt(BadList, i), ListGetAt(GoodList, i), "all");
}

However, I do recognize the code and it seems like it looks more complicated than it is and is almost cut and paste for looping. Interestingly on my first attempt the info variable did work. Thanks Dan really appreciated. Here's the UDF!
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