Wednesday, July 11, 2012

Representing quotes inside string in C#


For:
Ana said "apples"!

string myString = "Ana said \"apples\"!";
string myString = @"Ana said ""apples""!";

Rules:
 - add \ before quotes you want to keep;
 - double the quotes and use @ at the begining.

2 comments:

  1. Or using \":

    string myString = "Ana said \"apples\"!";

    ReplyDelete
  2. Thanks Tavi! I found that one too, but forgot to update the article :) I added it now.

    ReplyDelete