-
Notifications
You must be signed in to change notification settings - Fork 2
StringInterpolation
Manno edited this page May 19, 2016
·
15 revisions
The string interpolation example is an example on how to combine a 'template string' and variables. String interpolation is an alternative to the sometimes cumbersome string concatenation.
With string interpolation:
var name:String = "Arthur";
var score:Int = 42;
var output:String = 'Well done $name! You scored $score points';
trace( output ); // traces: Well done Arthur! You scored 42 points
Or to construct an SQL query (for SQLite perhaps?)
var name:String = "Arthur";
var score:Int = 42;
var sqlQuery:String = 'INSERT INTO scores( name, score ) VALUES ( "$name", $score)';
trace( sqlQuery ); // traces: INSERT INTO scores( name, score ) VALUES ( "Arthur", 42)
Without string interpolation:
var name:String = "Arthur";
var score:Int = 42;
var output:String = 'Well done " + name + "! You scored " + score + " points';
trace( output ); // traces: Well done Arthur! You scored 42 points