How do I write the escape char '\\' to cod

2019-01-07 23:42发布

问题:

How to escape the character \ in C#?

I did search in the Internet, but didn't find anything.

回答1:

You just need to escape it:

char c = '\\';

Or you could use the Unicode escape sequence:

char c = '\u005c';

See my article on strings for all the various escape sequences available in string/character literals.



回答2:

You can escape a backslash using a backslash.

//String
string backslash = "\\";

//Character
char backslash = '\\';

or

You can use the string literal.

string backslash = @"\";
char backslash = @"\"[0];


回答3:

use double backlash like so "\"

"\\"

cause an escape



回答4:

If you want to output it in a string, you can write "\\" or as a character, you can write '\\'.



回答5:

Escape it: "\\"

or use the verbatim syntax: @"\"



回答6:

Double escape it. Escape escape = no escape! \\



回答7:

Or you can just ... Put

private void TxtBegin_TextChanged(object sender, EventArgs e)
{
    TxtBegin.Text = DateTime.Now.ToShortDateString();
}; 

that will give you the date Only ... and there DateTime.now.ToShortTimeString();



回答8:

You can use something like this:

@"\yourString";


标签: c# escaping