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

Search Paragraph and Hyperlink Certain Words

Explorer ,
Oct 06, 2008 Oct 06, 2008

Copy link to clipboard

Copied

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

TOPICS
Advanced techniques

Views

575

Translate

Translate

Report

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

correct answers 1 Correct answer

Community Expert , Oct 16, 2008 Oct 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.

Votes

Translate

Translate
Contributor ,
Oct 10, 2008 Oct 10, 2008

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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
Community Expert ,
Oct 16, 2008 Oct 16, 2008

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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
Explorer ,
Oct 16, 2008 Oct 16, 2008

Copy link to clipboard

Copied

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!

Votes

Translate

Translate

Report

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
Community Expert ,
Oct 17, 2008 Oct 17, 2008

Copy link to clipboard

Copied

No thanks.

Votes

Translate

Translate

Report

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
Explorer ,
Oct 26, 2008 Oct 26, 2008

Copy link to clipboard

Copied

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>."

Votes

Translate

Translate

Report

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
Community Expert ,
Oct 26, 2008 Oct 26, 2008

Copy link to clipboard

Copied

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


Votes

Translate

Translate

Report

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
Explorer ,
Oct 27, 2008 Oct 27, 2008

Copy link to clipboard

Copied

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:

Votes

Translate

Translate

Report

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
Community Expert ,
Oct 27, 2008 Oct 27, 2008

Copy link to clipboard

Copied

It's getting more ad hoc.

Votes

Translate

Translate

Report

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
Explorer ,
Oct 28, 2008 Oct 28, 2008

Copy link to clipboard

Copied

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:

Votes

Translate

Translate

Report

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
Community Expert ,
Oct 28, 2008 Oct 28, 2008

Copy link to clipboard

Copied

LATEST
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.




Votes

Translate

Translate

Report

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
Documentation