The strings in the database are already set? If so, can you show a few more examples?
Or, are you designing a new system that will both set and get the values?
For the first example you can do something like the following:
map = {
"{{{Year}}}" : year(now())
,"{{{MonthName}}}" : monthAsString(month(now()))
,...
};
formattedString = replace(inputString, map); // use replaceNoCase for case insensitive match
This style requires more work because you have to parse the values out. I’m not sure if these are 4 separate values or not since you didn’t elaborate much.
You can probably use REGEX to parse that, but whether that’s the best way in this case depends on many factors.
Another approach is to add functions to the map
described above, and parse the value before evaluating it in the map. For example:
map = {
"Year" : function() { return year(now()); }
,"MonthName" : function() { return monthAsString(month(now())); }
,"productsID" : function(arg) { /* select from db and return formatted string */ }
,...
};
// use regex to find the templates:
pattern="{{{[^}]+}}}";
regexResult = refind(pattern, templateString, 1, true);
if (!isEmpty(regexResult.pos)){
// you have template values, loop over regexResult.pos and regexResult.len
// arrays and get substrings from templateString
}
Then each template value should be handled, e.g.
templateValue = replaceList(templateValue, "{{{,}}}", ","); // remove braces
key = listFirst(templateValue, "=");
arg = (templateValue CT "=") ? listLast(templateValue, "=") : "";
if (map.keyExists(key){
func = map[key];
formattedString = func(arg);
}
else {
// error handling
}