string-interpolation Questions

4

Solved

Trying to interpolate an int value into a string using %v formatter as follows, yet nothing is printed, package main import "fmt" func inc(i int) int { return i + 1 } func main() { fmt.Sprint...
Ormandy asked 30/4, 2018 at 7:13

13

Solved

I'm looking for something to achieve the following: String s = "hello {}!"; s = generate(s, new Object[]{ "world" }); assertEquals(s, "hello world!"); // should be tru...
Length asked 28/6, 2013 at 12:20

6

Solved

I'm using the .format() a lot in my Python 3.5 projects, but I'm afraid that it will be deprecated during the next Python versions because of f-strings, the new kind of string literal. >>>...

4

Solved

I'm trying to create a string literal representing an array of JSON objects so I thought of using string interpolation feature as shown in the code below: public static void MyMethod(string abc, ...
Gusher asked 16/6, 2017 at 6:47

16

Solved

In PHP I am trying to create a newline character: echo $clientid; echo ' '; echo $lastname; echo ' '; echo '\r\n'; Afterwards I open the created file in Notepad and it writes the newline literal...
Chapland asked 21/11, 2010 at 14:47

4

Solved

PHP supports variable interpolation in double quoted strings, for example, $s = "foo $bar"; But is it possible to interpolate function call results in the double quoted string? For example, $s...
Converse asked 25/5, 2012 at 17:1

4

In Ruby I could do this. aaa = "AAA" bbb = "BBB #{aaa}" puts(bbb) > "BBB AAA" The point of this syntax is eliminating repetition, and making it to feel like a shell script - great for heavy...
Eyrir asked 24/1, 2014 at 4:47

20

Solved

Python has this beautiful function to turn this: bar1 = 'foobar' bar2 = 'jumped' bar3 = 'dog' foo = 'The lazy ' + bar3 + ' ' + bar2 ' over the ' + bar1 # The lazy dog jumped over the foobar Into ...
Mcdade asked 11/2, 2011 at 21:26

3

Solved

The alignment component is the -20 in this example: $"{value, -20}" Is there a way to make an interpolated string like this: $"{value, alignment}" where alignment is a variable?
Wantage asked 25/7, 2018 at 17:28

18

Solved

I know in PHP we can do something like this: $hello = "foo"; $my_string = "I pity the $hello"; Output: "I pity the foo" I was wondering if this same thing is possible in JavaScript as well. Usi...
Chirm asked 21/7, 2010 at 21:28

3

Solved

I am writing files to disk using Scala. To create the whole String that will be written to the file, I am currently iterating over my data and appending all the information to a StringBuilder obje...
Saxen asked 31/7, 2015 at 16:54

3

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...

3

Html portion $html = @($htm) $html = @" <!doctype html> <html lang="en"> <head> <body> text $computername $username text </body> </html> &quot...
Schindler asked 3/10, 2023 at 11:47

13

Solved

I have several text files in which I have introduced shell variables ($VAR1 or $VAR2 for instance). I would like to take those files (one by one) and save them in new files where all variables wou...
Viva asked 4/1, 2013 at 10:43

2

Solved

Typical string formatting in powershell for instance to use padding or specifying number can be written like this: >>> "x={0,5} and y={1:F3}" -f $x, $y x= 10 and y=0.333 But in Powershe...
Spillage asked 4/4, 2020 at 9:42

6

Solved

Since I am using Java 14 and 15 preview features. Trying to find the string interpolation in java. The closest answer I found is String.format("u1=%s;u2=%s;u3=%s;u4=%s;", u1, u2, u3, u4) ...
Pencel asked 24/8, 2020 at 10:27

4

Solved

I am somewhat new to Java but I dislike the heavy use of string concatenation I'm seeing in my textbook. For example, I'd like to avoid doing this: String s = "x:"+x+"," y:"+y+", z:"+z; Is it p...
Mockingbird asked 30/3, 2011 at 0:37

3

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/a...
Joachima asked 8/11, 2019 at 16:25

4

Solved

I am trying to get an email template together. The message content will be dependent on values within a dictionary. However, the dictionary might not contain all the keys each time. This currently...
Kailey asked 22/1, 2015 at 17:5

16

Solved

I want to do the following in C# (coming from a Python background): strVar = "stack" mystr = "This is %soverflow" % (strVar) How do I replace the token inside the string with the value outside o...
Swearword asked 19/2, 2012 at 22:59

15

Solved

I am using template strings to generate some files and I love the conciseness of the new f-strings for this purpose, for reducing my previous template code from something like this: template_a = &q...
Cornelia asked 27/2, 2017 at 23:24

2

Solved

In C# 11 we can now include newlines in an interpolated string. So we can write code like this: string pageTitle = ""; string header = $"Header: { pageTitle switch { "&quot...
Vladi asked 6/4, 2023 at 20:45

3

Solved

C# uses string interpolation int value = 100; Console.WriteLine($"The size is {value}."); Output: The size is 100. How to do the same thing in TypeScript?
Baird asked 30/7, 2017 at 12:44

8

I want to create a string with embedded information. One way (not the only way) of achieving what I want is called string interpolation or variable substitution, wherein placeholders in a string ar...
Ivonneivor asked 21/6, 2016 at 23:16

1

Solved

I don't understand why this will not compile when typed out in a .cshtml/Razor page: @($"{"\""}") // <-- does not work @($"{"'"}") // <-- does no...

© 2022 - 2024 — McMap. All rights reserved.