String escape double quote
The following asp.net c# example code demonstrate us how can we escape
double quote in a string programmaticallyat run time in an asp.net
application. .Net framework's String Class represent text as a series of
Unicode characters.We can escape double quotes (") in a string by
several ways.
We can escape double quotes in a string by using a escape character Backslash (\). If we want to include a doublequotes in this way, we should write the string as ("a \"sample\" text"). Here the word (sample) will be surrounded by twodouble quotes as "sample".
We also can escape double quotes in a string object by using @ symbol. If we want to write the same string in this technique,then we should format it as (@"a ""sample"" text"). Here we also need to place a double quotes two times to get output a single doublequotes. Both techniques show the same output.
We can escape double quotes in a string by using a escape character Backslash (\). If we want to include a doublequotes in this way, we should write the string as ("a \"sample\" text"). Here the word (sample) will be surrounded by twodouble quotes as "sample".
We also can escape double quotes in a string object by using @ symbol. If we want to write the same string in this technique,then we should format it as (@"a ""sample"" text"). Here we also need to place a double quotes two times to get output a single doublequotes. Both techniques show the same output.
string-escape-double-quote.aspx
<%@ Page Language="C#" AutoEventWireup="true"%>
<!DOCTYPE html>
<script runat="server">
protected void Button1_Click(object sender, System.EventArgs e)
{
//this section create string variable with double quote.
string stringPlants = "\"Brown Betty\" \"Meadow Cabbage\" \"Swamp Cabbage\"";
//another way to escape double quote in string
string stringPlants2 = @"""California Sycamore"" ""California Walnut"" ""Canada Root""";
Label1.Text = "string of plants..................<br />";
Label1.Text += stringPlants;
Label1.Text += "<br />"+stringPlants2;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>c# example - string escape double quote</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:MidnightBlue; font-style:italic;">
c# example - string escape double quote
</h2>
<hr width="550" align="left" color="Gainsboro" />
<asp:Label
ID="Label1"
runat="server"
Font-Size="Large"
>
</asp:Label>
<br /><br />
<asp:Button
ID="Button1"
runat="server"
Text="string escape double quote"
OnClick="Button1_Click"
Height="40"
Font-Bold="true"
/>
</div>
</form>
</body>
</html>