par , 15/12/2018 à 00h32 (901 Affichages)
Les strings template permette d’insérer des variables dans une string sans faire de concaténation.
Je me suis amusé à vous les énumérer dans 7 langages différent :
1 2 3
| $text = 'World';
echo "Hello $text !"; |
1 2 3 4
| import java.text.MessageFormat;
Object[] params = new Object[]{"hello", "!"};
String msg = MessageFormat.format("{0} world {1}", params); |
1 2 3
| text = "world";
puts("Hello #{text} !"); |
1 2 3
| var template = "Hello %@ !";
someLabel.text = String(format: template, "world"); |
1 2 3 4
| from string import Template
s = Template('Hello $text !');
s.substitute(text='world'); |
1 2 3
| let text = "world";
console.log(`Hello ${text} !`); |
1 2 3
| string text = "world";
Console.WriteLine("Hello {0} !", text); |