string-interpolation

What is the optional argument in C# interpolated string for?

北城余情 提交于 2019-11-30 00:15:48
问题 Interpolated strings is one of the new features of C# 6.0. According to MSDN, the syntax of the embedded C# expressions can contain an optional, comma-separated value, deemed as <optional-comma-field-width> in the documentation. Unfortunately I didn't find what this field is for. From its name one might think that this value sets the maximal size of the "interpolated" field, but when I try the following expression: var p = Process.GetCurrentProcess(); Console.WriteLine($"Process name is {p

What is the default culture for C# 6 string interpolation?

丶灬走出姿态 提交于 2019-11-29 15:56:33
问题 In C# 6 what is the default culture for the new string interpolation? I've seen conflicting reports of both Invariant and Current Culture. I would like a definitive answer and I'm keeping my fingers crossed for Invariant. 回答1: Using string interpolation in C# is compiled into a simple call to String.Format . You can see with TryRolsyn that this: public void M() { string name = "bar"; string result = $"{name}"; } Is compiled into this: public void M() { string arg = "bar"; string text = string

How to manually interpolate a string? [duplicate]

大憨熊 提交于 2019-11-29 13:41:09
This question already has an answer here: How replace variable in string with value in php? 11 answers The only way I've found to interpolate a string (I.E. expand the variables inside it) is the following: $str = 'This is a $a'; $a = 'test'; echo eval('return "' . $str . '";'); Keep in mind that in a real-life scenario, the strings are created in different places, so I can't just replace ' s with " s. Is there a better way for expanding a single-quoted string without the use of eval()? I'm looking for something that PHP itself provides. Please note : Using strtr() is just like using something

String interpolation, escaping quotation mark

青春壹個敷衍的年華 提交于 2019-11-29 10:51:46
I'm somewhat baffled by how difficult this turns out to be. I've already looked around stackoverflow, but no solution seems to work fine for me. What I want to do: val file = checkcache(fileName) file match { case Some(_) => {println(s"File $file found!"); file.get} case None => createFile(fileName) } Now, this works perfectly fine, for a file named "blubb" that already resides in the cache it outprints File blubb found and returns the file. Now I want this to be File "blubb" found So I tried doing this: case Some(_) => { println(s"File \" $file \" found!"); file.get} Compiler throws ')'

Why can't _ be used inside of string interpolation?

对着背影说爱祢 提交于 2019-11-29 05:59:05
This works (x => s"$x") but this (s"${_}") gives [error] ...: unbound placeholder parameter [error] (s"${_}") Is this just because the s"..." construct suffers from Leaky Abstraction ? Furthermore: (s"$_") fails with a completely different output: [error] ...: invalid string interpolation: `$$', `$'ident or `$'BlockExpr expected [error] (s"$_") [error] ^ [error] ...: unclosed string literal [error] (s"$_") kiritsuku Calling string interpolation a leaky abstraction is totally right in my opinion. While it works fine in most cases, there are many edge cases where it just doesn't work the way how

How to make string interpolation in typescript? [duplicate]

时光怂恿深爱的人放手 提交于 2019-11-29 05:23:49
This question already has an answer here: How can I do string interpolation in JavaScript? 18 answers C# uses string interpolation int value = 100; Console.WriteLine($"The size is {value}."); Output: The size is 100. How to make same method in typescript? Nitzan Tomer In JavaScript you can use template literals : let value = 100; console.log(`The size is ${ value }`); Ygalbel Just use special ` var lyrics = 'Never gonna give you up'; var html = `<div>${lyrics}</div>`; You can see more examples here . 来源: https://stackoverflow.com/questions/45399951/how-to-make-string-interpolation-in

C# 6 how to format double using interpolated string?

谁说我不能喝 提交于 2019-11-29 04:21:25
问题 I have used some new features of C# 6 incl. interpolated string for simple usage (showing message which contains string variables like $"{EmployeeName}, {Department}"). Now I want to use interpolated string for showing formatted double value. Example var aNumberAsString = aDoubleValue.ToString("0.####"); How can I write it as interpolated string? something like $"{aDoubleValue} ...." 回答1: You can specify a format string after an expression with a colon ( : ): var aNumberAsString = $"

Parsing string interpolation in ANTLR

别来无恙 提交于 2019-11-29 03:59:53
问题 I'm working on a simple string manipulation DSL for internal purposes, and I would like the language to support string interpolation as it is used in Ruby. For example: name = "Bob" msg = "Hello ${name}!" print(msg) # prints "Hello Bob!" I'm attempting to implement my parser in ANTLRv3, but I'm pretty inexperienced with using ANTLR so I'm unsure how to implement this feature. So far, I've specified my string literals in the lexer, but in this case I'll obviously need to handle the

Interpolation within single quotes

牧云@^-^@ 提交于 2019-11-29 03:42:42
How can I perform interpolation within single quotes? I tried something like this but there are two problems. string = 'text contains "#{search.query}"' It doesn't work I need the final string to have the dynamic content wrapped in double quotes like so: 'text contains "candy"' Probably seems strange but the gem that I'm working with requires this. You can use %{text contains "#{search.query}"} if you don't want to escape the double quotes "text contains \"#{search.query}\"" . Ahmed Eshaan 'Hi, %{professor}, You have been invited for %{booking_type}. You may accept, reject or keep discussing

Angular - Interpolate string with html

心不动则不痛 提交于 2019-11-28 23:45:25
So i've got a "template string" that looks like this: var templateString = "Hello my name is {{name}}"; The name that I want to interpolate is a in variable. So I proceeded this way: var miniScope = { name: "Chuck" }; var sentence = $interpolate(templateString)(miniScope); /* sentence: "Hello my name is Chuck" */ This works. Now I'd like to bold the name. I've obviously tried: var miniScope = { name: "<strong>Chuck</strong>" }; But the html code gets escaped. Any idea how I can achieve this? PS: For those of you who wonder why I don't just put the string in the template, it's because my