3 ms·
C#6 string interpolation is glorious, but if you use the multiline var myString = $@" Hey, string interpolation is nifty. Look ma, no { this.Hands.
by Pxtl 11y ago
C#6 string interpolation is glorious, but if you use the multiline
var myString = $@"
Hey, string interpolation is nifty.
Look ma, no { this.Hands.ToString().ToUpper() }
More text.
But this is a ""quote"". It's ""ugly"" isn't it?
";
As you can see, you need to double your double quotes to escape them. Almost perfect. You can even nest string interpolations to do next template stuff with functional-programming loops and whatnot.
- virtualwhys 11y agoScala seems to do what you want: val str = s""" Tripe quoted string interpolation Allows for $variables and ${method.foo(bar)} Mixed with "quotes" """ Can also use double quoted string interpolation for inline/one-liners where embedded quotes above aren't needed.
- insulanian 11y agoF# can have quotes inside triple-quoted string like Scala, sans interpolation.
- Pxtl 11y agoNeat! With facilities like that, Id be tempted to skip templating libraries altogether and just have a normal interface for templates and use the regular string expressions... Unless I needed then internationalized, and that's where Mustache shines, IMHO.