by vorg · 10y ago · 0 comments
You're both wrong. String interpolation is just a very thin syntactic layer. It's easy enough to write
printf("Half of %f is: %f5.2", someVal, someVal * 0.5)
instead of print("Half of $someVal is: ${someVal * 0.5}")
and a lot easier for a programming language to parse, without needing to feed the parser into the lexer. And you also get easy formatting of the decimal (e.g. %f5.2), whereas string interpolation (in Swift, Apache Groovy, etc) requires a separate call, e.g. print("Half of $someVal is: ${format(someVal * 0.5, "%f5.2")}")https://msdn.microsoft.com/en-us/library/dn961160.aspx#Ancho...
$"Name = {name}, hours = {hours:hh}"
var s = $"hello, {name}"
System.IFormattable s = $"Hello, {name}"
System.FormattableString s = $"Hello, {name}"
$"{person.Name, 20} is {person.Age:D3} year {(p.Age == 1 ? "" : "s")} old."