interpolation

Haxe string interpolation.


Keywords
cross, sys, utility
License
MIT
Install
haxelib install interpolation 0.9.1

Documentation

Interpolation

Build Status

You can use interpolation to perform string interpolation, using $ to identify the variables in the string :

Install

haxelib install interpolation

Using

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 $, you can use $$ :

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".

Feature

PEP209 Simpler String Substitutions

TODO

  • PEP3101 Advanced String Formmating