Javascript 如何在 TypeScript 中执行字符串插值?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45399951/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 03:02:55 来源:igfitidea点击:
How to perform string interpolation in TypeScript?
提问by zshanabek
C# uses string interpolation
C# 使用字符串插值
int value = 100;
Console.WriteLine($"The size is {value}.");
Output:
输出:
The size is 100.
大小为 100。
How to do the same thing in TypeScript?
如何在 TypeScript 中做同样的事情?
回答by Nitzan Tomer
In JavaScript you can use template literals:
在 JavaScript 中,您可以使用模板文字:
let value = 100;
console.log(`The size is ${ value }`);

