I need an expert advise on following scenario. I have a string template (lets assume email templates) as follows.
Dear {PERSON_NAME},
We would like to thank you on behalf of {CEO_NAME}, {COMPANY_NAME}. You have been selected
for the position of {POSITION_NAME} in {DEPARTMENT_NAME}
etc etc
Here is replacement code
String body = getTemplateBody(tempalteId);
sendMail(
body.replace("{PERSON_NAME}", personName )
.replace("{CEO_NAME}", ceoName),
.replace("{COMPANY_NAME}", companyName),
.replace("{POSITION_NAME}", positionName),
.replace("{DEPARTMENT_NAME}", deptName),
.replace("{X}", someVar1),
.replace("{Y}", someVar2),
.replace("{Z}", someVar3),
.replace("{ETC_ETC}", "etc")
);
What we have:
- 20 variables enclosed with { }, like
{PERSON_NAME}
- These variables are fixed not changing in single template string.
- These variables are unique, none of the variables is repeated again in same template
- 10,000 instances of each template is used in one hour. do daily would be (10,000 * 24)
Question: what is the efficient(not elegant) way to replace variables in a template string to get the actual resultant string
Efficient in terms of memory first and then processing
?
Would there be any memory leakage
or any problem
in above code?
Please note above code is just a sample to explain my requirements in simple words, and may not be checked for Variable or method names coding standards.