Skip to main content
Inspiring
October 6, 2008
Answered

Search Paragraph and Hyperlink Certain Words

  • October 6, 2008
  • 10 replies
  • 717 views
I have a column that can be up to 2000 characters long. When displaying the content, I want to create a link on certain items ("ClientID-"). There can be multiple items per record.

Database String:
I just got a call from Sally (ClientID-324). She said that Martin (ClientID-3456453) and Matt (ClientID-65744) were going to be late for the meeting.

Displayed Value:
I just got a call from Sally (<a href="displayClient.cfm?id=324">ClientID-324</a>). She said that Martin (<a href="displayClient.cfm?id=9958997">ClientID-9958997</a>) and Matt (<a href="displayClient.cfm?id=65744">ClientID-65744</a>) were going to be late for the meeting.

This would give the end user the ability to click on "ClientID-????" and view the details page. The ClientID number can vary between 1 to 7 numbers and are always displayed after "ClientID-".

So, I was the code to search for "ClientID-", find the number proceeding the "ClientID-" and add the code to make it a link.

I looked at some of the CF Functions (Replace, Find, REFind, ReplaceNoCase, ReplaceList, REReplace) but my small brain found not figure it out.

Thanks for the help,

James
Sacramento, CA

This topic is closed to new replies. Start a new post to keep the conversation going.
Correct answer BKBK
Here is a fully worked out example. It runs through quite a few themes. Have a look. There are a number of ways to customize it and make it your own.

10 replies

BKBK
Community Expert
Community Expert
October 29, 2008
I don't know where you got the "08-1241-223, 07.1002120 or 09.312.1923" strings from...

Force of habit. I've often had to desanitize telephone numbers like that. When you said, "a way to delimit the items like before as sometimes theres a space, a comma, or other charactor.", I thought you meant there could be characters that delimit the sequence of integers. I now know what you meant.

I modified your code to look for my number string as long as it doesn't start with a "=" or ">" (used in my link).

OK. The trick is to search with a regex that the replacement strings will never match. Otherwise you'll risk ending up in an infinite loop.

Good luck.




BKBK
Community Expert
Community Expert
October 27, 2008
It's getting more ad hoc.
unleashedAuthor
Inspiring
October 28, 2008
Thanks BKBK,

I don't know where you got the "08-1241-223, 07.1002120 or 09.312.1923" strings from... The strings that I will be looking for are all just 9 numbers with no punctuation. So, I didn't need the first two "replace" tags you gave me.

I modified your code to look for my number string as long as it doesn't start with a "=" or ">" (used in my link). I instructed the end users not to enter the number like "blah=083212333".

Here is my finished code:

BKBK
Community Expert
Community Expert
October 27, 2008
What is your code for String ="Look up event 08-1241-223, 081251222 and 07.1002120. The current event=09.312.1923."?


unleashedAuthor
Inspiring
October 27, 2008
I'm collecting the string from user input. The string is just being queried from a database.

I figured out the regular expression I want, but I'm having an issue with looping and replacing. This is what I have so far:

BKBK
Community Expert
Community Expert
October 17, 2008
No thanks.

unleashedAuthor
Inspiring
October 27, 2008
BKBK,,, I have another one along the sames lines for you... If you could help me out.

I've tried to work this out myself and either can't figure out the looping or the regular expression.

I want to search a string for a 9 charactor string that starts with "06, 07, 08, or 09". I couldn't find a way to delimit the items like before as sometimes theres a space, a comma, or other charactor.

Ie. String ="Look up event 081241223, 081251222 and 071002120. The current event=093121923."

Should be (pysdo) = "Look up event <a href=page.cfm?id=081241223>081241223</a>, <a href=page.cfm?id=081251222>081251222</a> and <a href=page.cfm?id=071002120>071002120</a>. The current event=<a href=page.cfm?id=093121923>093121923</a>."
BKBK
Community Expert
BKBKCommunity ExpertCorrect answer
Community Expert
October 16, 2008
Here is a fully worked out example. It runs through quite a few themes. Have a look. There are a number of ways to customize it and make it your own.

unleashedAuthor
Inspiring
October 16, 2008
BKBK, you the man (or woman)... I actually got this working and it's similar to your code, but yours is MUCH cleaner... I was doing the same thing with a cfloop, cfabort and using a list with a funky " " delimiter. Trust me, the code was funky, but it kind of worked (as a concept) until you helped me out. THANKS!
Participating Frequently
October 10, 2008
You can use the CF List functions to parse the string. Using "(" and ")" as delimiters will allow you to parse the ClientID-nnnn occurrences in the string. Within that, using "-" as the delimiter will allow you to isolate the numeric portion. From that you can build the HTML for the link. The use Replace function to replace the original string with the HTML.