Questions tagged [string-interpolation]

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.

https://en.wikipedia.org/wiki/String_interpolation

1093 questions
-1
votes
3 answers

Trying to understand how `${c}` in this string interpolation points to the elements in an array

const continents = ['Africa', 'America', 'Asia', 'Australia', 'Europe']; const helloContinents = Array.from(continents, c => `Hello ${c}!`); const message = helloContinents.join(' '); const element = React.createElement("div", { title: "Outer…
-1
votes
1 answer

Extra quotes when logging objects with NLog

I have a code that outputs interpolated string to the log with NLog. Here is an example _logger.LogDebug($"REQUEST {webRequest.RequestUri}", Id) WebResponse webResponse = await _httpService.SendRequestAsync(webRequest); var response =…
Andrey Dengin
  • 181
  • 2
  • 15
-1
votes
1 answer

Conditional string interpolation

What's wrong with the syntax below? I want to assign x to {diff} short of if diff > 0 otherwise it shall be an empty string. diff = 1 x = f"{diff 'short of' if diff > 0 else ''}" EDIT: Based on the comment, it seems that the right way to do this…
dragonfly02
  • 3,403
  • 32
  • 55
-1
votes
2 answers

Angular 7 Cannot read the property email of undefined

I just want to display the email of this logged in user in the header Here is my AuthService: import { Injectable } from '@angular/core'; import { HttpClient, HttpHeaders } from '@angular/common/http'; import { Observable } from 'rxjs'; import { map…
-1
votes
1 answer

Given value is not assigned in the if statement in Spark Scala?

I have assigned following values. Issue with this is that end1 and end2 values are not assigned when used inside the if statement. I have used string interpolation but still not assigned My sample code is like this , three if conditions , one is…
-1
votes
2 answers

How do I capture a regex greedily based on a different situation?

Currently, I am trying to implement string interpolation for my language. The string interpolation looks something like this: let x = " Baby" let message = "Hello $(x)" My current regex to capture interpolated expression is: const regex =…
Wong Jia Hau
  • 2,639
  • 2
  • 18
  • 30
-1
votes
2 answers

TypeScript string interpolation not working in Angular project service file

Following is code for an Angular project service: @Injectable() export class FetchDataService { fetch(link){ console.log('this is a ${link}'); } } I'm calling this method in the component passing a string as an arguement. Console…
-1
votes
1 answer

How do you put quotes around variables when using complex commands and C# interpolation?

I am trying to perform a Robocopy of a file. The command I'm using (below) works when the "filename" variable does not contain spaces. How can I write this command to ignore spaces in this variable? System.Diagnostics.Process.Start("robocopy.exe", …
dguth8
  • 29
  • 1
  • 5
-1
votes
3 answers

controller not actualize string interpolation

I got a problem My hellow.component.html is:

{{hello}}

and hellow.component.ts is: import { Component, OnInit } from '@angular/core'; @Component({ selector: 'app-hellow', …
-1
votes
3 answers

Taking a string, reversing the letter in each word while leaving the word in its original position

I am trying to take a sentence, and reverse the positions of the letters in each word. Below is my code that does not work: def test(sentence) array = [] array << sentence.split array.collect {|word| word.reverse} end My problem is with: array…
-1
votes
2 answers

Pass active record attributes in a method

I have a method, that takes an array of rails active record objects and sort those records based on the second parameter passed into the method. The method looks something like : def sort_provider(providers, attr) provider.sort!(|a,b| a."#{attr}"…
Dan
  • 25
  • 3
-1
votes
1 answer

Multi line conditional operator in string interpolation in C# fails

var condition = false; Foo($"String is {(condition ? "True" : "False")} works"); but Foo($"String is {(condition ? "True" : "False")} fails"); I got compile error when I nicely format the conditional operator within my…
-1
votes
2 answers

How to pass variable into SQL string

I have one spark sql query which is accepting value as long. Dataset getQuery = spark.sql("select * from trafficdata where message_time between 1486036800000 and 1486108800000 ") i want this time to be as variables like Long val1 =…
priyanka Dhiman
  • 95
  • 3
  • 11
-1
votes
2 answers

Enumerate inside a string

I'm trying to enumerate an array inside a string, and have the values of the array interpolate inside of string. Example: todos = ["sleep", "eat", "powernap"] "Today I have todo: \n" + '#{todos.each do |todo| }' "\t #{todo}"…
Mitch Kroska
  • 325
  • 4
  • 15
-1
votes
2 answers

Cascading string interpolation in python

Given a dictionary of format strings, I want to do cascading/recursive string interpolation. FOLDERS = dict(home="/home/user", workspace="{home}/workspace", app_project="{workspace}/{app_name}", …
Laurent LAPORTE
  • 21,958
  • 6
  • 58
  • 103