Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Coldfusion REReplace question

Posted on 2011-09-15
8
487 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
ID: 36545828
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
ID: 36545872
@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
ID: 36545922
@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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 63

Expert Comment

by:Zvonko
ID: 36545992
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
 
LVL 1

Author Comment

by:roger_v
ID: 36546116
@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
ID: 36546188
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
ID: 36546327
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
ID: 36546653
<|:-)
0

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As most anyone who uses or has come across them can attest to, regular expressions (regex) are a complicated bit of magic. Packed so succinctly within their cryptic syntax lies a great deal of power. It's not the "take over the world" kind of power,…
Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
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…

839 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