String interpolation issues

The problem with this line Assert.AreEqual(formatted, $”{{countdown|{date:o}}}”); is that you have 3 curly quotes after the format string of the variable to be escaped and it starts escaping from left to right, therefore it treats the first 2 curly quotes as part of the format string and the third curly quote as the closing one. … Read more

Using C# 6 features with CodeDomProvider (Roslyn)

Update: March 2018 Word of caution, NuGet version 1.0.6 … 1.0.8 will not copy the /roslyn folder to the build output directory on non-web projects. Best stick with 1.0.5 https://github.com/aspnet/RoslynCodeDomProvider/issues/38 Run-time compilation using C#6 features requires a new compiler, as @thomas-levesque mentioned. This compiler can be installed by using the nuget package Microsoft.CodeDom.Providers.DotNetCompilerPlatform. For desktop … Read more

How do I convert a string into an f-string?

f-strings are code. Not just in the safe, “of course a string literal is code” way, but in the dangerous, arbitrary-code-execution way. This is a valid f-string: f”{__import__(‘os’).system(‘install ransomware or something’)}” and it will execute arbitrary shell commands when evaluated. You’re asking how to take a string loaded from a text file and evaluate it … Read more

f-strings vs str.format()

I’m afraid that it will be deprecated during the next Python versions Don’t be, str.format does not appear (nor has a reason) to be leaving any time soon, the PEP that introduced fprefixed-strings even states in its Abstract: This PEP does not propose to remove or deprecate any of the existing string formatting mechanisms. Formatted … Read more

Why does interpolating a const string result in a compiler error?

Interpolated strings are simply converted to calls to string.Format. So your above line actually reads private const string WEB_API_PROJECT = string.Format(“{0}project.json”, WEB_API_ROOT); And this is not compile time constant as a method call is included. On the other hand, string concatenation (of simple, constant string literals) can be done by the compiler, so this will … Read more

Does Python do variable interpolation similar to “string #{var}” in Ruby? [duplicate]

Python 3.6+ does have variable interpolation – prepend an f to your string: f”foo is {bar}” For versions of Python below this (Python 2 – 3.5) you can use str.format to pass in variables: # Rather than this: print(“foo is #{bar}”) # You would do this: print(“foo is {}”.format(bar)) # Or this: print(“foo is {bar}”.format(bar=bar)) … Read more

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

s is actually a method on StringContext (or something which can be implicitly converted from StringContext). When you write whatever”Here is text $identifier and more text” the compiler desugars it into StringContext(“Here is text “, ” and more text”).whatever(identifier) By default, StringContext gives you s, f, and raw* methods. As you can see, the compiler … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)