How to Add Double Quotes to a String That Is Inside a Variable

How can I add double quotes to a string that is inside a variable?

You need to escape them by doubling them (verbatim string literal):

string str = @"""How to add doublequotes""";

Or with a normal string literal you escape them with a \:

string str = "\"How to add doublequotes\"";

Add double quotes to string which is stored in variable

var audioUrl = "\""+ data.url+  "\""; 

Whatever your get audioUrl and you want to wrap it with ", you need to put them and escape inner ones with . Above will result in:

 "http://xxxxx/xxx/xx-xx-123.m4a"

OR if you are using the single quotes then no need to use the escape character.

var audioUrl = '"'+ data.url+  '"'; 

How to add double quotes around a String variable in Java?

There are actually 2 issues with your code.

  1. You need to make sure that \" is a String. This can be done by surrounding it with double quotes like this: "\""

  2. You need to concatenate Strings when printing them by using a +

Change the last line of code in your question to:

System.out.println("\"" + upperCasePhrase + "\"");

C# appending string from variable inside double quotes

A string.Format method placeholder is enough to concatenate instance without cutting through quote signs ({0} is the placeholder):

var table = string.Format(@"<table id=""table_id{0}"" class=""display"">", instance); 

Or you can use escape sequence \" for escaping quotes without string literal:

var table = "<table id=\"table_id" + instance + "\" class=\"display\">"

Result:

<table id="table_id1234" class="display">

Demo: .NET Fiddle

Put a variable inside double quoted string, but as function parameter in a nested for loop

just use quotes...

soup.select_one(f'a:contains("{m}")')


Related Topics



Leave a reply



Submit