String interpolation is the replacement of defined character sequences in a string by given values. This representation may be considered more intuitive for formatting and defining content than the composition of multiple strings and values using concatenation operators. String interpolation is typically implemented as a language feature in many programming languages including PHP, Haxe, Perl, Ruby, Python, C# (as of 6.0) and others.
Questions tagged [string-interpolation]
1093 questions
-2
votes
1 answer
C# String Interpolation and the Conditional Operator
How I can return null in the string if my {condition} is false. I'm using string interpolation with the conditional operator.
string returnURL = $"{ condition ? (ConfigurationManager.AppSettings["ApplicationURL"]}/my-page/{trip?.TripUId }) : null"

awais
- 492
- 4
- 17
-2
votes
2 answers
How do I display a default source if the first one fails?
I got this case where I am trying to display a general image if the image doesn't exit on the server.
I want to make it using ternary operator, but the "src" doesn't apply to the second condition.

Andrew
- 57
- 9
-2
votes
1 answer
Interpolation C# in foreach loop, how to do that
I have following code in my programm:
string[] strarray = new string[] {bird, lion, ape};
Array.Reverse(strarray);
strarray.Reverse();
foreach(var value in strarray)
{
…

G.Don
- 17
- 6
-2
votes
2 answers
What's the difference between these six Ruby string syntaxes, are they concatenation, interpolation or maybe something else
I was trying to write a single string across multiple lines since it was too long and I arrived at this solution that I think looks best but I couldn't find anything about it in the Ruby documentation
my_original = 'what I originally had ' +
…

Mendoza
- 82
- 7
-2
votes
4 answers
Performance difference between C# 6.0 "string" and $"string"
I have 2 codes in C# 6.0:
Sample 1:
string bar;
// ... some code setting bar.
var foo =
"Some text, " +
$"some other {bar}, " +
"end text.";
Sample 2:
string bar;
// ... some code setting bar.
var foo =
$"Some text, " +
$"some…

Jonny Piazzi
- 3,684
- 4
- 34
- 81
-2
votes
1 answer
Interpolating a string in c#
I want to use string interpolation for the below:
payloadArgs = string.Format("{0}TrackingID: \"{1}\"", payload.ToString().Replace("\n", "; "), trackingId);
I have tried
payloadArgs = $"{trackingId} TrackingId, \"{payload.ToString().Replace("\n",…

Our Man in Bananas
- 5,809
- 21
- 91
- 148
-2
votes
2 answers
i am trying to display the text of UI on label,what seems to be the issue?
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var manu_label: UILabel!
@IBAction func buttonpresses(_ sender: UIButton) {
let title=sender.title(for:[])
manu_label.text="you clicked \(title))…

Manan Jain
- 27
- 5
-2
votes
1 answer
How can I use string interpolation to sequentially name instances of an object?
I have a class called Team. I am trying to create many instances of it and call them team1, team2, etc. I am trying something like
for x in (1..20)
instancename="team#{x}"
instancename=Team.new
end
I am getting the memory address of the string…

user809334
- 45
- 3
-2
votes
1 answer
Why isn't this directive template interpolated?
What am I missing?
app.directive('summaryAddress', [function () {
return {
scope: {
address: '=summary-address'
},
template: "
Billing Address
" + "{{address.flatNumber}}" …
Ian Warburton
- 15,170
- 23
- 107
- 189
-3
votes
2 answers
Is it quicker to use string.Format or interpolation with $"..."?
Of these two methods of string interpolation (string.Format and the "$" operator), is one better than the other and if so, in what situations and why?
Examples of both doing the same thing:
//string.Format
string s = string.Format("( {0} ) , ( {1}…

Alfie Goodacre
- 2,753
- 1
- 13
- 26
-4
votes
2 answers
How to preserve null values in string interpolation C#
I want to keep the null values (insert them to DB) while i pass them over as a string to the sql variable in my C# code.
var valString = new StringBuilder();
//somevalue is null at this point
valString.Append($"({id}, " +$"'{SomeValue}')");
The…

Vah Run
- 11,223
- 2
- 11
- 15
-4
votes
1 answer
Abusing C# 6.0's new interpolated strings
I think the interpolated strings from C# 6.0 are by far the most practical. However, what's the point of using interpolation if your string looks like this:
string str0 = $"{chatType + prefix + group + name} > {message}";
How would you format this?…

ThuggerThug
- 1
- 3
-4
votes
1 answer
ruby expression for string interpolation
name = "James Kirk", starship = "USS Enterprise"
Given the variables above, write a Ruby expression that uses string interpolation in order to produce: "The captain of the USS Enterprise is James Kirk"

Sandeep Chahal
- 27
- 4