Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 535
  • Last Modified:

Coldfusion REReplace question

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
roger v
Asked:
roger v
  • 4
  • 4
1 Solution
 
ZvonkoSystems architectCommented:
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
 
roger vAuthor Commented:
@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
 
roger vAuthor Commented:
@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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
ZvonkoSystems architectCommented:
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
 
roger vAuthor Commented:
@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
 
roger vAuthor Commented:
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
 
ZvonkoSystems architectCommented:
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
 
ZvonkoSystems architectCommented:
<|:-)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now