string-interpolation

How can you use an object's property in a double-quoted string?

烈酒焚心 提交于 2019-11-25 22:58:41
问题 I have the following code: $DatabaseSettings = @(); $NewDatabaseSetting = \"\" | select DatabaseName, DataFile, LogFile, LiveBackupPath; $NewDatabaseSetting.DatabaseName = \"LiveEmployees_PD\"; $NewDatabaseSetting.DataFile = \"LiveEmployees_PD_Data\"; $NewDatabaseSetting.LogFile = \"LiveEmployees_PD_Log\"; $NewDatabaseSetting.LiveBackupPath = \'\\\\LiveServer\\LiveEmployeesBackups\'; $DatabaseSettings += $NewDatabaseSetting; When I try to use one of the properties in a string execute command:

Swift 3 incorrect string interpolation with implicitly unwrapped Optionals

会有一股神秘感。 提交于 2019-11-25 22:30:11
问题 Why are implicitly unwrapped optionals not unwrapped when using string interpolation in Swift 3? Example : Running the following code in the playground var str: String! str = \"Hello\" print(\"The following should not be printed as an optional: \\(str)\") produces this output: The following should not be printed as an optional: Optional(\"Hello\") Of course I can concatenate strings with the + operator but I\'m using string interpolation pretty much everywhere in my app which now doesn\'t

How can I do string interpolation in JavaScript?

北城以北 提交于 2019-11-25 22:25:54
问题 Consider this code: var age = 3; console.log(\"I\'m \" + age + \" years old!\"); Are there any other ways to insert the value of a variable in to a string, apart from string concatenation? 回答1: Since ES6, you can use template literals: const age = 3 console.log(`I'm ${age} years old!`) P.S. Note the use of backticks: `` . 回答2: tl;dr Use ECMAScript 2015's Template String Literals, if applicable. Explanation There is no direct way to do it, as per ECMAScript 5 specifications, but ECMAScript 6