Sebastion,

The code below should do it.  Note that this method (both your version and 
mine) will choke if the keyword list contains "pan" or "coldfusion,fusion" 
because of interference between the replacement of a string and the added 
<span> text, or between the replacement of one string and the replacement of 
another.

Completely unrelated note (I just didn't want to send out a separate message to 
deal with this):
If you post a question to multiple lists, please indicate that you've done so.

-David

<!--- Set the highlight style --->
<style type="text/css">
...highlight { background-color: yellow }
</style>

<cfset Keywords = 'cold,web,server'>
<cfset OpenTag = '<span class="highlight">'>
<cfset CloseTag = '</span>'>

<cfloop index="x" from="1" to="#ListLen(Keywords)#">
        <cfset HighlightedWord = OpenTag & ListGetAt(Keywords,x)  & CloseTag>
        <cfset String = REReplaceNoCase(String, "("&ListGetAt(Keywords,x)&")", 
OpenTag&"\1"&CloseTag, "ALL")>
</cfloop>

<cfoutput>#String#</cfoutput>


On Wednesday, May 30, 2001 5:13 PM, sebastian palmigiani [SMTP:[EMAIL PROTECTED]] 
wrote:
>
> I want to develop a highlight function of search terms. The following works
> well except that it changes the case of the keyword in the output. For
> example, 'Cold' in the original becomes 'cold' in the output.
>
> What can I include in the code to keep the original case of the String? If I
> use REReplace() then I omit the keywords because of case sensitivity.
>
> Sebastian
>
> -----------------------------
>
>
> <cfset String = 'Cold Fusion is a rapid application development system for
> professional  developers who want to create dynamic Web applications and
> interactive Web sites. It provides the fastest way to integrate browser,
> server, and database technologies into powerful Web applications. With Cold
> Fusion, you can build everything from online stores to sophisticated
> business systems.'>
>
> <!--- Set the highlight style --->
> <style type="text/css">
> ..highlight { background-color: yellow }
> </style>
>
> <cfset Keywords = 'cold,web,server'>
> <cfset OpenTag = '<span class="highlight">'>
> <cfset CloseTag = '</span>'>
>
>
> <cfloop index="x" from="1" to="#ListLen(Keywords)#">
>
> <cfset HighlightedWord = OpenTag & ListGetAt(Keywords, x)  & CloseTag>
>
> <cfset String= REReplaceNoCase(String, ListGetAt(Keywords, x),
> HighlightedWord, "ALL")>
>
> </cfloop>
>
> <cfoutput>#String#</cfoutput>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm

Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to