string-interpolation

What am I doing wrong with string interpolation in c#?

一曲冷凌霜 提交于 2020-04-17 22:45:13
问题 What I am doing: I am trying to build a dictionary in one function ( DictionaryBuilder ), extract a string from said dictionary and apply variables to it in another function ( QuestionGenerator ). Thus each time QuestionBuilder is called, the same string will be returned with differing contents without having to remake the same dictionary repeatedly. int a; int b; string theQuestion; string theAnswer; Dictionary<string, string> questionDict = new Dictionary<string, string>(); void

Is there a formatted byte string literal in Python 3.6+?

北城以北 提交于 2020-04-10 06:47:10
问题 I'm looking for a formatted byte string literal. Specifically, something equivalent to name = "Hello" bytes(f"Some format string {name}") Possibly something like fb"Some format string {name}" . Does such a thing exist? 回答1: No. The idea is explicitly dismissed in the PEP: For the same reason that we don't support bytes.format() , you may not combine 'f' with 'b' string literals. The primary problem is that an object's __format__() method may return Unicode data that is not compatible with a

How do I use String interpolation in a Groovy multiline string?

笑着哭i 提交于 2020-03-18 03:09:12
问题 In Groovy, I have a multiline String, defined with ''' , in which I need to use interpolation in order to substitute some other variables. For all my efforts, I can't get it to work -- I assume I need to escape something, which I'm missing. Here's some sample code: def cretanFood = "Dakos" def mexicanFood = "Tacos" def bestRestaurant = ''' ${mexicanFood} & ${cretanFood} ''' print bestRestaurant At the moment, this outputs: ${mexicanFood} & ${cretanFood} while I would clearly expect: Tacos &

Interpolate JSON values into a string

落花浮王杯 提交于 2020-03-03 09:15:33
问题 I am writing an application/class that will take in a template text file and a JSON value and return interpolated text back to the caller. The format of the input template text file needs to be determined. For example: my name is ${fullName} Example of the JSON: {"fullName": "Elon Musk"} Expected output: "my name is Elon Musk" I am looking for a widely used library/formats that can accomplish this. What format should the template text file be? What library would support the template text file

Interpolate JSON values into a string

老子叫甜甜 提交于 2020-03-03 09:15:22
问题 I am writing an application/class that will take in a template text file and a JSON value and return interpolated text back to the caller. The format of the input template text file needs to be determined. For example: my name is ${fullName} Example of the JSON: {"fullName": "Elon Musk"} Expected output: "my name is Elon Musk" I am looking for a widely used library/formats that can accomplish this. What format should the template text file be? What library would support the template text file

VueJS - Interpolate a string within a string

混江龙づ霸主 提交于 2020-02-28 13:34:32
问题 In VueJS, is there a way to interpolate a string within a string, either in the template or in the script? For example, I want the following to display 1 + 1 = 2 instead of 1 + 1 = {{ 1 + 1 }} . <template> {{ myVar }} </template> <script> export default { data() { "myVar": "1 + 1 = {{ 1 + 1 }}" } } </script> Edit: to better illustrate why I would need this, here's what my actual data looks like: section: 0, sections: [ { inputs: { user: { first_name: { label: "First Name", type: "text", val:

Difference between String interpolation and String concatenation

孤者浪人 提交于 2020-02-20 06:10:27
问题 When specifically dealing with non-optional String values, what could be the difference between String interpolation and String concatenation? struct MyModel { let value1: String let value2: String var displayNameByConcatenation: String { return value1 + "-" + value2 } var displayNameByInterpolation: String { return "\(value1)-\(value2)" } } Is there going to be any case where displayNameByConcatenation and displayNameByInterpolation are different? Like on long unicode strings? Is it possible

c# - dynamic string interpolation [duplicate]

只愿长相守 提交于 2020-01-31 18:08:33
问题 This question already has answers here : Is there a “String.Format” that can accept named input parameters instead of index placeholders? [duplicate] (9 answers) Closed 2 years ago . I'm trying to format some string dynamically with available variables in a specific context/scope. This strings would have parts with things like {{parameter1}} , {{parameter2}} and these variables would exist in the scope where I'll try to reformat the string. The variable names should match. I looked for

c# - dynamic string interpolation [duplicate]

蓝咒 提交于 2020-01-31 18:07:52
问题 This question already has answers here : Is there a “String.Format” that can accept named input parameters instead of index placeholders? [duplicate] (9 answers) Closed 2 years ago . I'm trying to format some string dynamically with available variables in a specific context/scope. This strings would have parts with things like {{parameter1}} , {{parameter2}} and these variables would exist in the scope where I'll try to reformat the string. The variable names should match. I looked for

jq not replacing json value with parameter

梦想的初衷 提交于 2020-01-30 05:21:45
问题 test.sh is not replacing test.json parameter values ($input1 and $input2). result.json has same ParameterValue "$input1/solution/$input2.result" [ { "ParameterKey": "Project", "ParameterValue": [ "$input1/solution/$input2.result" ] } ] test.sh #!/bin/bash input1="test1" input2="test2" echo $input1 echo $input2 cat test.json | jq 'map(if .ParameterKey == "Project" then . + {"ParameterValue" : "$input1/solution/$input2.result" } else . end )' > result.json 回答1: shell variables in jq scripts