Concatenate string values
Use string backtick template.
A backtick template is composed of a tag followed by a backtick string, enclosed within the backtick notation, where you can have expressions that are enclosed in ${...}
.
Bad Code
int age = 10;
string name = "Anne";
log:printInfo("Child name is " + name + " and age is " + age.toString());
- Need to convert non string values to strings.
- Need to handle spaces in the text properly along with the
+
.
Good Code
int age = 10;
string name = "Anne";
log:printInfo(string `Child name is ${name} and age is ${age}`);