Skip to content

imcj/interpolation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Haxe string interpolation.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published