按模板从文本中解析数据

时间:2016-03-31 08:23:21

标签: groovy

有没有办法从字符串中获取数据知道其模板? 我的意思是例如

def template = "${person} came up with the idea to collect ${item}."
def text = "Peter came up with the idea to collect coins."

然后检索Petercoins

1 个答案:

答案 0 :(得分:0)

如果您的模板是一个常规字符串(GString),那么您可以使用getStrings()getValues()方法访问它的每个部分。

请参阅the "toString" implementation of a GString