Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dollar Sign Character in Strings

What is the cleanest method for adding a $ character in a string literal?

The best solution I've come up with so far is """${"$"}...""", which looks ugly to me.

like image 286
Travis Avatar asked Jun 07 '15 06:06

Travis


People also ask

How do you put a dollar sign in a string?

In Interpolated Strings, the dollar sign ($) is used to tell the C# compiler that the string following it is to be interpreted as an Interpolated String. The curly braces encapsulate the values (of the variables) to include in the text. Note: you can include the literal curly braces by using “{{“ and “}}” accordingly.

What is '$' in Python?

To Python, those dollar signs mean nothing at all. Just like the 'D' or 'a' that follow, the dollar sign is merely a character in a string. To your source-code control system, the dollar signs indicate a substitution command.

What does ${} In JavaScript mean?

It's used to reference a variable within string: let someVar = "World!" console. log(`Hello ${someVar}`); // Output is Hello World!

How do you put dollar signs in string flutters?

Just put \$ and then works.


1 Answers

To escape the dollar sign inside a string literal, use the backslash character:

"\$" 

To escape it in a raw string literal ("""..."""), the workaround you provided is indeed the easiest solution at the moment. There's an issue in the bug tracker, which you can star and/or vote for: KT-2425.

like image 94
Alexander Udalov Avatar answered Sep 30 '22 18:09

Alexander Udalov