|
Mailing Lists
|
Home / Groups / ColdFusion Talk (CF-Talk)
REReplaceNoCase and dynamic query columnsI 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 |
February 08, 2012
|
Latest Fusion Authority Articles
|
|||||||||||||||||||||||||||||||||||||||||||||||||