Sitemap

Member-only story

C# Escape Characters

2 min readDec 20, 2022

--

Press enter or click to view image in full size
escape characters

In C#, there are several special characters called escape characters that can be used to represent certain characters within a string. These characters are represented by a backslash () followed by a letter or symbol.

Here is a list of some common escape characters in C#:

  • \': Single quote
  • \": Double quote
  • \\: Backslash
  • \0: Null
  • \a: Alert
  • \b: Backspace
  • \f: Form feed
  • \n: New line
  • \r: Carriage return
  • \t: Horizontal tab
  • \v: Vertical tab

For example, if you want to include a double quote character within a string that is surrounded by double quotes, you can use the escape character \":

string s = "This is a string with a \" character in it.";

You can also use escape characters to include special characters in a string that is surrounded by single quotes. For example:

string s = 'This is a string with a \n character in it.';

This will create a new line within the string.

It’s worth noting that in C#, you can also use verbatim strings to include special characters in a string without…

--

--

Albatros
Albatros

Written by Albatros

I explain how emerging technology changes the products you use, the money you spend, and the data you share. Evidence-led, practical, no hype.