-1

when I got a string of blank("") and I try to set it on clipboard on a button press , The program crash.

Let says

 this.button1.onclick+=new Eventhandler(clicked);

method

 void onclick(object sender,EventArge e)
      {
        clipboard.Settext(textbox1.Text); // textbox1.text is blank
      }

When I clicked the button, it crashes.

Can someone help me with this?

Poomrokc The 3years
  • 1,099
  • 2
  • 10
  • 23

3 Answers3

6

You need to excape it with \

string example = "\"";

or with @ (as Daniel suggested)

string example = @"""";
Kamil Budziewski
  • 22,699
  • 14
  • 85
  • 105
0

You need to escape it like this:

var example = "\"";

Or use a verbatim string literal with a double ":

var example = @"""";
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Simon Whitehead
  • 63,300
  • 9
  • 114
  • 138
0

" is an escape sequence character.

You need to escape it with \ like;

string example = "\"";

From Escape Sequences

Escape Sequence -- Represents
\"              -- Double quotation mark 

From Wikipedia

In many programming languages escape sequences are used in character literals and string literals, to express characters which are not printable or clash with the syntax of characters or strings. The escape character is usually the backslash. For example the single quotation mark character might be expressed as '\'' since writing ''' is not acceptable.

As an alternative, you can use your string as a verbatim string literal.

From 2.4.4.5 String literals

A verbatim string literal consists of an @ character followed by a double-quote character, zero or more characters, and a closing double-quote character. A simple example is @"hello". In a verbatim string literal, the characters between the delimiters are interpreted verbatim, the only exception being a quote-escape-sequence.

string example = @""";
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364