You can use interpolation to perform string interpolation, using $ to identify the variables in the string :
haxelib install interpolation
import interpolation.Template;
var template = new Template("My name is $name.");
var context:Hash<Dynamic> = new Hash();
context.set("name", "cj");
trace(template.substitute(context));
// will trace "My name is cj".
You can also use {} curly braces to enclose a whole expression :
var template = new Template("My name is ${name}.");
var context:Hash<Dynamic> = new Hash();
context.set("name", "cj");
trace(template.substitute(context));
// will trace "My name is cj".
If you want to output a single
var template = new Template("My name is $$name.");
var context:Hash<Dynamic> = new Hash();
context.set("name", "cj");
trace(template.substitute(context));
// will trace "My name is $name".
PEP209 Simpler String Substitutions
- PEP3101 Advanced String Formmating