Home > OS >  how to convert the double qoute to backtick
how to convert the double qoute to backtick

Time:05-09

I'm trying to create a message string with a dynamic variable.

var name="venkat";
var message ="hello ${name}"

but this does not works, so i use backtick to achieve this

var name="venkat";
var message =`hello ${name}`

My question is there is any way to covert "" => ``

CodePudding user response:

When not accessing object properties, you should simply use the dollar sign, without the brackets:

String name = "venkat";
String message = "Hello $name";

For accessing an object property:

Person newPerson = Person(name: "venkat");
String message = "Hello ${newPerson.name}";

Or do you have other reasons why you want to programmatically swap double quotes for backticks?


String interpolation

CodePudding user response:

Try below code, you can test below code here

void main() {
  var name = "venkat";
  var message = 'hello $name';
  print(message);
}
  • Related