执行冻结代码存储在一个字符串动态? [英] Execute coldfusion code stored in a string dynamically?

查看:108
本文介绍了执行冻结代码存储在一个字符串动态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个电子邮件正文在数据库中存储为字符串,如下所示:

I have an email body stored as a string in a database, something like this:


这是一个包含大量不同的变量。亲爱的#名字#,< br /> 请联系#代表姓名了解更多详情。

This is an email body containing lots of different variables. Dear #name#, <br/> Please contact #representativeName# for further details.

我使用存储的过程从数据库中拉取这个字段,然后我想在coldfusion端评估它,所以不用#name#,它会插入名称变量的值。

I pull this field from the database using a stored proc, and then I want to evaluate it on the coldfusion side, so that instead of "#name#", it will insert the value of the name variable.

我已经尝试使用评估,但只有只有一个变量名,这似乎才起作用。它会抛出一个错误,因为其他文本。

I've tried using evaluate, but that only seems to work if there's just a variable name. It throws an error because of the other text.

(我不能只使用占位符和这样的查找/替换 - 在Coldfusion字符串中解析变量,因为将其存储在数据库中的全部是变量用于构建字符串是动态的,例如,在一种情况下,名称字段可以称为名称,另一个可以是firstName等。)

(I can't just use placeholders and a find/replace like this - Resolving variables inside a Coldfusion string, because the whole point of storing this in a database is that the variables used to build the string are dynamic. For example, in one case the name field can be called "name" and in another it could be "firstName", etc.)

推荐答案

我将循环遍历每个#variableName#引用,并将其替换为评估版本。

I would loop over each #variableName# reference and replace it with the evaluated version.

正则表达式将能够找到他们全部然后是一个循环,让他们全部过来,并逐一评估一下。

A regex will be able to find them all and then a loop to go over them all and just evaluate them one by one.

这篇关于执行冻结代码存储在一个字符串动态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆