How to concatenate double quotes ("") with the string in asp.net(C#, VB)

IntroductionIn previous articles i explained How to Convert Rupees,Currency or Numbers to Words in Asp.net and Create crystal reports in visual studio 2010 and How to create and consume WCF Services and  How to Split large string separated by comma in Sql Server and Backup and restore sql server database and Convert/downgrade SQL Server 2012,2008 database to SQL Server 2005 or lower version .
In this article i am going to explain with example How to concatenate double quotes ("") with the string in asp.net using both the C# and VB.Net language.

Description: Using \" we can concatenate double quotes ("") with the string in C# and using """" we can concatenate double quotes ("") with the string in VB. Suppose you have a string variable strName having string value "Asp.net" and on print it will print as Asp.net without apostrophe but if you want to print it as “Asp.net”  i.e. in apostrophe then you have to concatenate your string with double quotes on both sides. But if you write as we normally do to concatenate like:

C#.NET Code
  • In the code behind file(.aspx.cs) write following code on Button click or any event as per your application requirement
  protected void Button1_Click(object sender, EventArgs e)
        {
            string strName = "Asp.net";
            string newStr=""" + strName + """'; // it will not work. so comment this line and write as below:
            string newStr="\"" + strName + "\"";
            Response.Write(newStr); //it will print "Asp.net"
        }

VB.NET Code
  • In the code behind file(.aspx.vb) write following code on Button click or any event as per your application requirement
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim strName As String = "Asp.net"
        Dim newStr As String = """" & strName & """"
        Response.Write(newStr)
    End Sub

Now over to you:
"If you like my work; you can appreciate by leaving your comments, hitting Facebook like button, following on Google+, Twitter, Linked in and Pinterest, stumbling my posts on stumble upon and subscribing for receiving free updates directly to your inbox . Stay tuned and stay connected for more technical updates."
Previous
Next Post »

1 comments:

Click here for comments
Unknown
admin
May 16, 2013 ×

what a valueable post.... i was looking for the same content.....

Congrats bro Unknown you got PERTAMAX...! hehehehe...
Reply
avatar

If you have any question about any post, Feel free to ask.You can simply drop a comment below post or contact via Contact Us form. Your feedback and suggestions will be highly appreciated. Also try to leave comments from your account not from the anonymous account so that i can respond to you easily..