[thelist] Help with a replace loop

Seth Bienek seth at sethbienek.com
Tue Jun 12 13:10:34 CDT 2001


Hi Shinji,

> The terms are unique; what's happening is that terms sometimes
> appear inside the #definition# of other terms. So if the query returned:
> 
> Terms:      Definitions:
> e-mail      a way of sending messages over the Internet
> Internet    a global network of computers
> 
> The code produces this:
> 
> <a href="[url]" title="a way of sending messages over the <a href="[url]"
> title="a global network of computers">Internet</a>">E-mail</a> is the most
> popular part of the Internet.

It sounds like you want to replace only keywords that begin on a new line:

ReplaceNoCase(varcopy, Chr(13) & Chr(10) & "#term#",'<a> href="http:///term.cfm/#term_id#.cfm" title="#definition#">#term#</a>',"ALL")

The 'Chr(13) & Chr(10)' represents a line break in a text file.  Depending on what format the original text is (html, etc.) this may include more info, like <br>'s, etc.

> Here's the code again:
> <cfloop query="getTerms">
>     <cfif FindNoCase(#term#,varcopy) is not 0>
>         <cfset varcopy = ReplaceNoCase(varcopy,#term#,'<a
> href="http:///term.cfm/#term_id#.cfm"
> title="#definition#">#term#</a>',"ALL")>
>     </cfif>    
> </cfloop>

Also, I haven't been following the thread closely, but the FindNoCase condition doesn't seem to be actually performing any function.  It can be omitted.  Try this:

<cfloop query="getTerms">
   <cfset varcopy = ReplaceNoCase(varcopy, Chr(13) & Chr(10) & getTerms.term, "<a href=""http:///term.cfm/#term_id#.cfm" title=""#definition#"">#getTerms.term#</a>", "ALL")>
</cfloop>

If this doesn't work or get you headed in the right direction, please include a sample of what the #varcopy# variable value looks like and we'll go from  there.

Best Regards,

Seth






More information about the thelist mailing list