CS_0016_Strings1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace string1
{
class Program
{
static
void
Main(string[] args)
{
string
myString1 = " Go to your C:\\
drive"; //
Escape Characters //
string
myString2 = " My \"So
Called\" Life!";
string
myString3 = " What if I need a \n
new line?";
Console.WriteLine(myString1);
Console.WriteLine(myString2);
Console.WriteLine(myString3);
Console.ReadLine();
//Results:
//Go to your C:\ drive
//My "So Called" Life!
//What if I need a
// new line?
}
}
}
https://blogs.msdn.microsoft.com/csharpfaq/2004/03/12/what-character-escape-sequences-are-available/
C# defines the following character escape sequences:
\'– single quote, needed for character literals\"– double quote, needed for string literals\\– backslash\0– Unicode character 0\a– Alert (character 7)\b– Backspace (character 8)\f– Form feed (character 12)\n– New line (character 10)\r– Carriage return (character 13)\t– Horizontal tab (character 9)\v– Vertical quote (character 11)\uxxxx– Unicode escape sequence for character with hex value xxxx\xn[n][n][n]– Unicode escape sequence for character with hex value nnnn (variable length version of \uxxxx)\Uxxxxxxxx– Unicode escape sequence for character with hex value xxxxxxxx (for generating surrogates)
Of these,
\a, \f, \v, \x and \U are rarely used in my experience.
Comments
Post a Comment