string interpolation

Solutions on MaxInterview for string interpolation by the best coders in the world

showing results for - "string interpolation"
Julia
29 Apr 2018
1// To use interpolation in strings, put the name of the relevant
2// variable between brackets {} and put a dollar sign $ in front
3// of the string. This will tell C# to use interpolation.
4double a = 3;
5double b = 4;
6Console.WriteLine($"Area of {a} and {b} is {0.5 * a * b}");
Marco
23 Jan 2020
1int age = 22;
2
3Console.WriteLine($"Age: {age}");
Emanuela
22 Apr 2020
1/*In order to embed expressions within normal strings,
2you would use the following syntax:*/
3let a = 5;
4let b = 10;
5console.log('Fifteen is ' + (a + b) + ' and\nnot ' + (2 * a + b) + '.');
6// "Fifteen is 15 and
7// not 20."
8
9/*Now, with template literals, you are able to make use of the syntactic sugar,
10making substitutions like this more readable:*/
11let a = 5;
12let b = 10;
13console.log(`Fifteen is ${a + b} and
14not ${2 * a + b}.`);
15// "Fifteen is 15 and
16// not 20."
Manuel
24 May 2019
1var message1 = interpolate("turkey");
2console.log(message1); // "My favorite food is turkey!"
3
4var message2 = interpolate("tofurkey");
5console.log(message2); // "My favorite food is tofurkey!"
6
Nicola
26 Jan 2017
1const number = 42;
2const message = `The number is ${number}`;
3
4message; // => 'The number is 42'
similar questions
queries leading to this page
string interpolation