string-interpolation

Interpolating environment variables in string

别来无恙 提交于 2020-01-25 00:19:08
问题 I need to expand environment variables in a string. For example, when parsing a config file, I want to be able to read this... statsFile=${APP_LOG_DIR}/app.stats And get a value of "/logs/myapp/app.stats", where the environment variable APP_LOG_DIR = "/logs/myapp". This seems like a very common need, and things like the Logback framework do this for their own config files, but I have not found a canonical way of doing this for my own config files. Notes: This is not a duplicate of the many

Scala unbound placeholder parameter

我与影子孤独终老i 提交于 2020-01-13 10:27:09
问题 I am using the following code to meet my needs: (1 to 5)..map(i => s"\\x${i}") // Produces List("\\x1", "\\x2", "\\x3", "\\x4", "\\x5") But I would like to use a placeholder. According to the string interpolator documentation : (1 to 5).map(s"\\x${_}") should expand to: (1 to 5).map(StringContext("\\\\x","").s(_)) But the latter works, not the former, which throws an error: unbound placeholder parameter on _ . Why? 回答1: I believe with the syntax: (1 to 5).map(s"\\x${_}") The compiler believes

How do I format a string with string interpolation in Scala as a fixed width string?

匆匆过客 提交于 2020-01-11 01:26:51
问题 I'm interfacing with a really old system and the file I need to generate needs a field that is a formed from a string but needs to be exactly 15 in width. I want something like this: val companyName = "FooBar, Inc" // 11 chars f"$companyName%s" To return: " FooBar, Inc" Is there a slick way to do what I'm trying to do with the String interpolation? 回答1: Use String.format with a format string. Surely something there will do what you want :-) This code would do what you want: scala> val

How to use a variable in ts as a tagname in a HTML file? [duplicate]

北慕城南 提交于 2020-01-04 05:45:15
问题 This question already has answers here : Angular HTML binding (20 answers) Closed 3 months ago . I want to know if there is any way to use the HTML tag name (<p> for e.g.) which is obtained from a variable? The following is the code I tried: app.component.ts import { Component,OnInit } from '@angular/core'; @Component({ selector: 'my-app', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent implements OnInit{ name = 'Angular'; somevalues = [1,

New C# 6.0 String Interpolation statements don't compile [duplicate]

女生的网名这么多〃 提交于 2020-01-03 13:37:43
问题 This question already has answers here : What is the final format for string interpolation in VS 2015? (2 answers) Closed 4 years ago . I am trying to implement some of the features in this video but I'm not having much luck with the new String Interpolation syntax (I have everything else working, at least that's in this code). I am using Visual Studio 2015 CTP6, I have configured it to use .NET 4.6 and have gone into the Build options to make sure I was specifying C# 6.0. I have also

New C# 6.0 String Interpolation statements don't compile [duplicate]

百般思念 提交于 2020-01-03 13:37:10
问题 This question already has answers here : What is the final format for string interpolation in VS 2015? (2 answers) Closed 4 years ago . I am trying to implement some of the features in this video but I'm not having much luck with the new String Interpolation syntax (I have everything else working, at least that's in this code). I am using Visual Studio 2015 CTP6, I have configured it to use .NET 4.6 and have gone into the Build options to make sure I was specifying C# 6.0. I have also

tfs build server - string interpolation $ Character is not valid

陌路散爱 提交于 2020-01-03 07:37:09
问题 i am using string interpolation using $ in my code. It compiles fine but when i check in my code, the build server throws an error BC30037: Character is not valid . Following is an example on how i have used string interpolation: dim r = New RadNode($"{acq.FormNo} - ${CInt(acq.TotalAmount)}", icon:=RadTreeIcons.RedTriangle) The build server has Visual Studio 2015 Entreprise edition installed. If i run this from command prompt: C:\Program Files (x86)\MSBuild\14.0\Bin>MSBuild /tv:14.0 "Proj.sln

how to interpolate the section-name with configparser

泪湿孤枕 提交于 2020-01-03 03:34:07
问题 I'm using configparser to read configuration for a backup-system. one of the options (the output path) often includes the section-name itself. [DEFAULT] compression=gzip [foo] output=/Backups/foo/ [pizza] output=/BigDisk/Backups/ [bar] output=/Backups/bar/ Now I would like to get rid manually appending the section name, and instead would like to use string interpolation. Something like the following: [DEFAULT] compression=gzip output=/Backups/%(SECTION)s/ [foo] [pizza] output=/BigDisk/Backups

Is it possible to include a C# variable in a string variable without using a concatenator?

冷暖自知 提交于 2020-01-01 04:37:10
问题 Does .NET 3.5 C# allow us to include a variable within a string variable without having to use the + concatenator (or string.Format(), for that matter). For example (In the pseudo, I'm using a $ symbol to specify the variable): DateTime d = DateTime.Now; string s = "The date is $d"; Console.WriteLine(s); Output: The date is 4/12/2011 11:56:39 AM Edit Due to the handful of responses that suggested string.Format(), I can only assume that my original post wasn't clear when I mentioned " ...(or

Single quote string string interpolation

十年热恋 提交于 2019-12-30 09:07:28
问题 I am trying to set an email address within ActionMailer with Rails. Before it was hard coded, but we want to make them ENV variables now so we don't need to amend code each time an email changes. Here is how it's currently defined: from = '"Name of Person" <email@email.com>' I've tried setting the email as an environment variable using ENV['EMAIL'] but I'm having no luck even with #{ENV['EMAIL'} . Can anyone point me in the right direction? 回答1: You cannot use string interpolation with single