string-interpolation

Using expanding strings as Powershell function parameters

醉酒当歌 提交于 2020-08-02 17:48:09
问题 I'm trying to write a function that will print a user-supplied greeting addressed to a user-supplied name. I want to use expanding strings the way I can in this code block: $Name = "World" $Greeting = "Hello, $Name!" $Greeting Which successfully prints Hello, World! . However, when I try to pass these strings as parameters to a function like so, function HelloWorld { Param ($Greeting, $Name) $Greeting } HelloWorld("Hello, $Name!", "World") I get the output Hello, ! World Upon investigation,

Interpolate a string with bash-like environment variables references

吃可爱长大的小学妹 提交于 2020-07-08 11:49:47
问题 I have an input string for my Golang CLI tool with some references to environment variables in bash syntax ( $VAR and ${VAR} ), e.g.: $HOME/somedir/${SOME_VARIABLE}dir/anotherdir-${ANOTHER_VARIABLE} What is the most efficient way to interpolate this string by replacing environemnt variables references with actual values? For previous example it can be: /home/user/somedir/4dir/anotherdir-5 if HOME=/home/user , SOME_VARIABLE=4 and ANOTHER_VARIABLE=5 . Right now I'm using something like: func

Interpolate a string with bash-like environment variables references

主宰稳场 提交于 2020-07-08 11:45:36
问题 I have an input string for my Golang CLI tool with some references to environment variables in bash syntax ( $VAR and ${VAR} ), e.g.: $HOME/somedir/${SOME_VARIABLE}dir/anotherdir-${ANOTHER_VARIABLE} What is the most efficient way to interpolate this string by replacing environemnt variables references with actual values? For previous example it can be: /home/user/somedir/4dir/anotherdir-5 if HOME=/home/user , SOME_VARIABLE=4 and ANOTHER_VARIABLE=5 . Right now I'm using something like: func

C# 6.0 - Unexpected character '$' [closed]

别等时光非礼了梦想. 提交于 2020-07-03 06:13:43
问题 Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 2 years ago . Improve this question I'm new to programming and I have just installed Visual Studio 2017. I created this code (from the book I'm learning), but this does not compile. I have problem with string interpolation and I get error: Unexpected character '$', but I'm using C# 6.0 so this

C# Serilog: how to log with String interpolation and keep argument names in message templates?

左心房为你撑大大i 提交于 2020-05-30 06:45:27
问题 How to replace this code: string name = "John"; logger.Information("length of name '{name}' is {nameLength}", name, name.Length); with C# String interpolation like this or similar string name = "John"; // :-( lost benefit of structured logging: property names not passed to logger logger.Information($"length of name '{name}' is {name.Length}"); but keep the property names for structured logging to work? Benefits would be: Increased readability You'll never forget an argument in arguments list

C# Serilog: how to log with String interpolation and keep argument names in message templates?

安稳与你 提交于 2020-05-30 06:44:05
问题 How to replace this code: string name = "John"; logger.Information("length of name '{name}' is {nameLength}", name, name.Length); with C# String interpolation like this or similar string name = "John"; // :-( lost benefit of structured logging: property names not passed to logger logger.Information($"length of name '{name}' is {name.Length}"); but keep the property names for structured logging to work? Benefits would be: Increased readability You'll never forget an argument in arguments list

How to evaluate a variable as a Python f-string

瘦欲@ 提交于 2020-05-29 06:13:11
问题 I would like to have a mechanism which evaluates an f-string where the contents to be evaluated are provided inside a variable. For example, x=7 s='{x+x}' fstr_eval(s) For the usage case I have in mind, the string s may arise from user input (where the user is trusted with eval ). While using eval in production is generally very bad practice, there are notable exceptions. For instance, the user may be a Python developer, working on a local machine, who would like to use full Python syntax to

Why is this usage of python F-string interpolation wrapping with quotes?

断了今生、忘了曾经 提交于 2020-05-29 05:07:06
问题 Code in question: a = 'test' # 1) print(f'{a}') # test # 2) print(f'{ {a} }') # {'test'} # 3) print(f'{{ {a} }}') # {test} My question is, why does case two print those quotes? I didn't find anything explicitly in the documentation. The closest thing I found detailing this was in the PEP for this feature: (the grammar for F-strings) f ' <text> { <expression> <optional !s, !r, or !a> <optional : format specifier> } <text> ... ' The expression is then formatted using the format protocol, using

Scala interpolate String from variable

拟墨画扇 提交于 2020-05-16 05:22:07
问题 String interpolation works fine in this case: val name = "Bill" val result = s"My Name is ${name}" When I introduce it to the variable it didn't get interpolated value: val name = "Bill" val greeting = "My Name is ${name}" val result = s"${greeting}" Direct wrapping of greeting is not appropriate solution, I must handle greeting like a plain String. 回答1: String interpolation in Scala does not compose in the way you expect. The issue for this has been debated. Folks want it, but folks don't

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

前提是你 提交于 2020-04-17 22:50:29
问题 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