Quotes in Strings

Quotes in Strings

Verbatim Strings

  • A literal that starts with an @ character and the remaining characters are enclosed in double quotation marks
  • The @-quoted string tells the compiler not to process escape characters

Using Quotes in Strings

  • string is an alias for String in the .NET Framework
  • Use  \" in your string to put a double quote
  • Example: string stringToUpdate = "width=\"" + "16\"" + " height=\"" + "15\"";
  • Output: width="16" height="15"

String.Format

  • Use to support replaceable parameters
  • Example: string output = String.Format("width={0} height={1}, "\"16\"" "\"15"");

Sources