Related Posts Plugin for WordPress, Blogger...

About

Follow Us

Wednesday, 11 February 2015

Introduction: 

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
Categories: ,

0 comments:

Post a Comment