House of Fusion
Search over 2,500 ColdFusion resources here
  
Home of the ColdFusion Community

Mailing Lists
Home / Groups / ColdFusion Talk (CF-Talk)

REReplaceNoCase and dynamic query columns

Author:
Andy Matthews
02/01/2010 05:24 PM

I have a query containing multiple columns (30 or so). It's always a single record. I have a string which contains a key, wrapped in double %% symbols, that needs to be replace with the value of the same key from the query. For example, the string might have %%color%% which would correspond the color column from the query. I'm trying to use REReplaceNoCase to find the key, and replace it with the value. It "almost" works, but I can't seem to get it the last 5%. Here's some sample code <!--- sample query ---> <cfset REQUEST.myQ = QueryNew('vin,color')> <cfset QueryAddRow(REQUEST.myQ, 1)> <cfset QuerySetCell(REQUEST.myQ, 'vin', '1GNFC13C47J338994', 1)> <cfset QuerySetCell(REQUEST.myQ, 'color', 'Blue', 1)> <!--- the URL string ---> <cfset REQUEST.theURL = 'http://www.mydomain.com/mq.p?a=sp&vin=%%VIN%%'>; <!--- correctly replaces %%VIN%% from the string, with just VIN---> <cfset REQUEST.final = REReplaceNoCase(REQUEST.theURL, '%%(\w+)%%', "\1", 'ALL')> <!--- correctly replaces %%VIN%% with the value of VIN from the query---> <cfset REQUEST.final = REReplaceNoCase(REQUEST.theURL, '%%(\w+)%%', "#REQUEST.myQ['VIN'][1]#", 'ALL')> <!--- fails, with a "Missing argument name" error ---> <cfset REQUEST.final = REReplaceNoCase(REQUEST.theURL, '%%(\w+)%%', "#REQUEST.myQ[/\1][1]#", 'ALL')> <cfdump var="#REQUEST#"> Is it possible to do this in one line? I'm SO close, but it's just not working. Is it possible to dynamically evaluate the temp variable from the regular expression and use it as a ColdFusion variable? Andy matthews


Search cf-talk

February 08, 2012

<<   <   Today   >   >>
Su Mo Tu We Th Fr Sa
       1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29