Wednesday, 4 April 2012

TO PASS THE STRING ALONG WITH THE DOUBLE QUOTES IN C#


To display a string enclosed within a double quotes, we can use,

string str = "I like \"string\"";    -- Output: I like "string"  
string str = @"Here is my ""quoted"" text.";  -- Output: Here is my "quoted" text.

To display a string enclosed within a double quotes that is assigned a control value (eg:- label), we can use,

Label1.Text = "String";
string str = "\"" + Label1.Text + "\"";  -- Output: "String"

2 comments:

  1. This should work

    string str = @"" + Label1.Text + @""; -- Output: "String"

    ReplyDelete
  2. Those examples are ok while printing, but while Passing the string parameter (which contains "Quoted" text), it would pass an additional \(slash) before each "(double quote).

    ReplyDelete