Solved

Coldfusion REReplace question

Posted on 2011-09-15
8
482 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

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Whatever be the reason, if you are working on web development side,  you will need day-today validation codes like email validation, date validation , IP address validation, phone validation on any of the edit page or say at the time of registration…
This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
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…

773 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