Link to home
Start Free TrialLog in
Avatar of earwig75

asked on

Need help with Cold Fusion "Replace"

I have something like the below code. I have a variable called "monitor" that will contain a text string.  Sometimes this string will have something like ABC 1234 in it... If it does I want it stripped out/replaced with nothing. So, if my variable is "monitor ABC 7777" I just want it converted to "monitor". The ABC remains the same but the numbers can possibly be different.

Can someone help? Does what I have below look correct?

<cfhttpparam name="SendMonitor" type="CGI" value="#replace(URL.Monitor,"ABC %%%%","","all")#">

Open in new window

Avatar of SidFishes
Flag of Canada image

actually you can use the listFirst function by treating the space as a delimiter (as long as that is consistent)

<cfset vMonitor = listfirst(url.monitor, " ")>

if that doesn't work, you might want to look at using REReplaceNoCase which uses regex (which I suck at so I might not be able to help if that's the case)
Avatar of earwig75


Sometimes my string will be something like "Hello the device type is monitor ABC 7777 and it is blue".

But sometimes it will be "Hello the device type is desktop ABC 7878 and it is blue...

I would want either one of those converted to:  "Hello the device type is monitor and it is blue." Or... desktop etc...

Basically anytime ABC **** shows up in a string I want it stripped out - without it mattering what is before or after it.

Avatar of _agx_
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial