Template system (replace items in a string with items from a hash)


/ Published in: ActionScript 3
Save to your folder(s)

This simple construct allows you to replace parts of a string with items in a hash table (e.g. and Object).

Example:

var replacements : Object = { SPEED : "slow", ADJECTIVE : "green", VERB: "slithers" };

var template: String = "The %{SPEED} %{ADJECTIVE} fox %{VERB} over the %{ADJECTIVE} dog.";

trace( makeReplacements( template, replacements ) );

//output: The slow green fox slithers over the green dog.

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.