Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dart - How to Insert "$" word in String? [duplicate]

I'm currently creating an simple application with flutter(Dart). And when i want to create the AppBar widget, i cant give it names with '$'. Because, same like Kotlin..Dart is using '$' for summoning an identifier.

Any solution?

var _appbar = AppBar(
  title: Text("How I Made $100"), //$ is the error
);
like image 672
Haikal Permana Avatar asked Dec 05 '18 22:12

Haikal Permana


People also ask

How do you replace words in a Dart string?

To replace all the substring of a string we make use of replaceAll method in Dart. This method replaces all the substring in the given string to the desired substring. Returns a new string in which the non-overlapping substrings matching from (the ones iterated by from.

How do you replace a character in a string in darts?

To replace all occurrences of a substring in a string with new substring, use String. replaceAll() method. The method returns a new string with all string matchings of given pattern replaced with newSubString . You can give a string for pattern .

What is string interpolation in Dart?

String interpolation is the process of inserting variable values into placeholders in a string literal. To concatenate strings in Dart, we can utilize string interpolation. We use the ${} symbol to implement string interpolation in your code.


1 Answers

The dollar sign is a special character, so if you want it to be ignored you have to escape it with a \.

For example:

void main() {
  print("This string contains a dollar \$ign");
}

See this gist.

like image 162
rmtmckenzie Avatar answered Oct 21 '22 00:10

rmtmckenzie