How to concatenate a string whit "

  • Thread starter Thread starter Alessandro Rossi
  • Start date Start date
A

Alessandro Rossi

Hi,
I have this problem:
In C# i have to concatenate a string "hi Carl" with
another string like this """, but C# gives me an error.
How can i concatenate a string with the " character?

Thank you
Alessandro Rossi
 
Use an Escape Character before the quotation mark. The escape character is a
backslash '\'.

Example:

string str = "\"Hi Carl\"";

-Darrin
 
Alessandro said:
Hi,
I have this problem:
In C# i have to concatenate a string "hi Carl" with
another string like this """, but C# gives me an error.
How can i concatenate a string with the " character?

Thank you
Alessandro Rossi

In the middle of a string, use the escape character, \, followed by a "
to add a " to the string.

E.g.

String FOOBAR = "\" To defend everything is to defend nothing \" -
Alexander the great";

Would be become: "To defend everything is to defend nothing" - Alexander
the great

Simon.
 
Back
Top