I have a JavaScript variable:
var text = "http://example.com"
Text can be multiple links. How can I put '' around the variable string?
I want the strings to, for example, look like this:
"'http://example.com'"
Use a formatted string literal to add double quotes around a variable in Python, e.g. result = f'"{my_var}"' . Formatted string literals let us include variables inside of a string by prefixing the string with f .
If you have single quotes in the string, delimit it with double quotes. If you have double quotes in the string, delimit it with single quotes. If you need to use both types in the string, escape whatever delimiter you have chosen by prefixing it with a \ .
Strings are created by putting data inside the quotes. JavaScript and other programming languages allow the users to keep the data either in double quotes (" ") or single quotes (' ').
To do what you require you need to escape the single/double quotes within the name string. To do that you could use a regex: name = name. replace(/([\""|\''])/g, '\\$1'); $("#trID").
var text = "\"http://example.com\"";
Whatever your text, to wrap it with "
, you need to put them and escape inner ones with \
. Above will result in:
"http://example.com"
var text = "http://example.com";
text = "'"+text+"'";
Would attach the single quotes (') to the front and the back of the string.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With