Solved

Coldfusion REReplace question

Posted on 2011-09-15
8
470 Views
Last Modified: 2012-05-12
Hi Experts,

I have a need for a coldfusion rereplace that takes an existing string, searches for a set of words in that string, and then if it finds that set, then replaces just that specific set of words with a new set of words.

the string:
*************
strMyString = "School-Board-Hepson Junior High/LaSalle,South-Athletics Prog"

the string token to replace:
*********************************
<cfset strMyToken = "Hepson Junior High/LaSalle,South" />

the new token that replaces strMyToken:
*************************************************
<cfset strMyNewToken = "Hepson - Junior - High/LaSalle;South" />

So, once the string replacement is done, the new string looks like so:
***********************************************************************************
strMyString = "School-Board-"Hepson - Junior - High/LaSalle;South-Athletics Prog"
0
Comment
Question by:roger_v
  • 4
  • 4
8 Comments
 
LVL 63

Expert Comment

by:Zvonko
Comment Utility
But you did not set what is the criteria find the matching words.
If the matching words are exactly thos names that you stated above that is the Replace a simpele replace.
If not, then explan in plain English what the search criteria are.

Do you look for word do be "Hepson"? If not then what is the criteria to be the first word match?

0
 
LVL 1

Author Comment

by:roger_v
Comment Utility
@zvonko:

The search criteria is to look for an exact match of the variable strMyToken. Then replace this occurence in the strMyString string with the value in the variable strMyNewToken. I tried a ReReplaceNoCase(strMyString, strMyToken, strMyNewToken) but I'm not sure if that works.
0
 
LVL 1

Author Comment

by:roger_v
Comment Utility
@zvonko:

Here's the problem that I'm having: I think the rereplace is failing because there is a forward slash in the name and when I check the output in fiddler, coldfusion is placing a back slash before the forward slash to escape it. So this is what I have:

<cfset strOldString = qryGetNames.name />
<cfset strNewString = ReReplaceNoCase(strOldString,strMyToken,strMyNewToken) />

But since qryGetNames.name has the following : Hepson Junior High/LaSalle,South
Notice the forward slash between High and La, coldfusion is inserting a backslash before that like so:

Hepson Junior High\/LaSalle,South

As a result, the rereplacenocase is failing and also, I get an ajax error.
0
 
LVL 63

Expert Comment

by:Zvonko
Comment Utility
The Re Stands for RegularExpression. You do not want meta character as used in RegEx. You want exact character match. Therefore let that Re go and use simply: RepalceNoCase()
http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=functions_m-r_35.html



0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 1

Author Comment

by:roger_v
Comment Utility
@Zvonko:

I changed it to replacenocase, but in my ajax call I get an error:

"[Macromedia][SQLServer JDBC Driver][SQLServer]Incorrect syntax near 'SOUTH'."

In my actual code there is a space before SOUTH. Could that be the issue?
0
 
LVL 1

Author Comment

by:roger_v
Comment Utility
OK, I was making a stupid mistake and now it works. I don't get an error but it doesn't do the replace. For some reason, the replacenocase doesn't replace the old value with the new value.
0
 
LVL 63

Accepted Solution

by:
Zvonko earned 500 total points
Comment Utility
I do not know what you are doing but it is too simple:
<cfset strMyString = "School-Board-Hepson Junior High/LaSalle,South-Athletics Prog" >
<cfset strMyToken = "Hepson Junior High/LaSalle,South" />
<cfset strMyNewToken = "Hepson - Junior - High/LaSalle;South" />

<cfset strMyNewString = ReplaceNoCase(strMyString, strMyToken, strMyNewToken) >

<cfdump var="#strMyNewString#" >

Open in new window

0
 
LVL 63

Expert Comment

by:Zvonko
Comment Utility
<|:-)
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

I have been reconstructing a PHP-based application that has grown into a full blown interface system over the last ten years by a developer that has now gone into business for himself building websites. I am not incredibly fond of writing PHP code o…
Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now