string-interpolation

Can Perl string interpolation perform any expression evaluation?

岁酱吖の 提交于 2019-11-28 04:40:55
related to question: How do I substitute with an evaluated expression in Perl? In Perl, is there a way like in Ruby to do: $a = 1; print "#{$a + 1}"; and it can print out 2 ? There's a similar shorthand in Perl for this: $a = 1; print "@{[$a + 1]}" This works because the [] creates a reference to an array containing one element (the result of the calculation), and then the @{} dereferences the array, which inside string interpolation prints each element of the array in sequence. Since there is only one, it just prints the one element. You can use the @{[ EXPRESSION ]} trick that Greg Hewgill

String interpolation, escaping quotation mark

萝らか妹 提交于 2019-11-28 04:31:07
问题 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

How to make string interpolation in typescript? [duplicate]

放肆的年华 提交于 2019-11-27 22:54:20
问题 This question already has answers here : How can I do string interpolation in JavaScript? (17 answers) Closed 2 years ago . 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? 回答1: In JavaScript you can use template literals: let value = 100; console.log(`The size is ${ value }`); 回答2: Just use special ` var lyrics = 'Never gonna give you up'; var html = `<div>${lyrics}</div>`; You can see

How to use escape characters with string interpolation in C# 6?

我的未来我决定 提交于 2019-11-27 22:38:41
I've been using string interpolation and loving it, however I have an issue where I am trying to include a backslash in my output, but am not able to get it to work. What I want is something like this.. var domain = "mydomain"; var userName = "myUserName"; var combo = $"{domain}\{userName}" I want the output of combo to be myDomain\myUserName What I am getting is a syntax error about the \ being an escape character. If I put in \\ then the snytax error is gone, but the output is myDomain\\myUsername How can I include escaped characters in an interpolated string? birdamongmen Escaping with a

How do you use verbatim strings with interpolation?

跟風遠走 提交于 2019-11-27 19:12:25
In C#6 there is a new feature: interpolated strings. These let you put expressions directly into code, rather than relying on indexes: string s = string.Format("Adding \"{0}\" and {1} to foobar.", x, this.Y()); Becomes: string s = $"Adding \"{x}\" and {this.Y()} to foobar."; However, we have a lot of strings across multiple lines using verbatim strings (mainly SQL statements) like this: string s = string.Format(@"Result... Adding ""{0}"" and {1} to foobar: {2}", x, this.Y(), x.GetLog()); Reverting these to regular strings seems messy: string s = "Result...\r\n" + $"Adding \"{x}\" and {this.Y()

Interpolation within single quotes

点点圈 提交于 2019-11-27 17:54:24
问题 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. 回答1: You can use %{text contains "#{search.query}"} if you don't want to escape the double quotes "text contains \"#{search.query}\"" . 回答2: 'Hi,

What is the final format for string interpolation in VS 2015?

落爺英雄遲暮 提交于 2019-11-27 14:34:34
I can't get string interpolation to work. Last news from MS I found was http://blogs.msdn.com/b/csharpfaq/archive/2014/11/20/new-features-in-c-6.aspx However all that is said there is not working. Anyone knows if string interpolation made it into VS 2015? Is there any documentation about it? Can one you give an example? For instance, none of these formats work ( edited ): int i = 42; var s = "\{i}"; // correction after jon's answer: this works! var s = $"{i}"; // compiler error var s = "{{i}}"; // no interpolation edit about VS 2015 CTP 6 (20.4.2015 ) The final version is var s = $"{i}" also

Using C# 6 features with CodeDomProvider (rosyln)

做~自己de王妃 提交于 2019-11-27 13:30:18
CodeDomProvider objCodeCompiler = CodeDomProvider.CreateProvider( "CSharp" ); CompilerParameters objCompilerParameters = new CompilerParameters(); ... CompilerResults objCompileResults = objCodeCompiler.CompileAssemblyFromFile( objCompilerParameters, files.ToArray() ); When I compile my files I get: FileFunctions.cs(347): Error: Unexpected character '$' Does anyone know how to get string interpolation working with CodeDom compiling? I found this link: How to target .net 4.5 with CSharpCodeProvider? So I tried: var providerOptions = new Dictionary<string, string>(); providerOptions.Add(

String interpolation in Scala 2.10 - How to interpolate a String variable?

点点圈 提交于 2019-11-27 12:34:11
String interpolation is available in Scala starting Scala 2.10 This is the basic example val name = "World" //> name : String = World val message = s"Hello $name" //> message : String = Hello World I was wondering if there is a way to do dynamic interpolation, e.g. the following (doesn't compile, just for illustration purposes) val name = "World" //> name : String = World val template = "Hello $name" //> template : String = Hello $name //just for illustration: val message = s(template) //> doesn't compile (not found: value s) Is there a way to "dynamically" evaluate a String like that? (or is

String Interpolation vs String.Format

旧时模样 提交于 2019-11-27 12:15:51
Is there a noticable performance difference between using string interpolation: myString += $"{x:x2}"; vs String.Format()? myString += String.Format("{0:x2}", x); I am only asking because Resharper is prompting the fix, and I have been fooled before. Jeroen Vannevel Noticable is relative. However: string interpolation is turned into string.Format() at compile-time so they should end up with the same result. There are subtle differences though: as we can tell from this question, string concatenation in the format specifier results in an additional string.Concat() call. string interpolation is