Inserting a Double Quote in to a String in .NET

Posted: January 4, 2008 in .Net
Tags: , , ,
Even though this is not new I do forget this always, so thought of putting an entry on how we can put a double quote inside of a string.
 
VB.NET
Dim str As String = "Example String " & """" & "This is the String with double quotes." & """"
MessageBox.Show(str)
In VB.Net you can indicate that there is a double quote in a string by using 4 double quotes ("""").
 
C#.NET
string str = "Example String " + "\"" + "This is the String with double quotes." + "\"";
MessageBox.Show(str);

As you will notice in C# the double quote can be represented as double quote, back slash and again using two double quotes ("\"").

The above string will be displayed as follows.

image

Advertisement
Comments
  1. Ragunath says:

    Nice……. It works fine Thanks..:)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s