How to write an escape character in a string?

How to write escape character "\" to string?

+3
source share
6 answers

In the normal line you use \\

If it is in regular expression, it should be \\\\

The reason RegEx needs four is because both the line parser and the RegEx engine are accelerated. Therefore, it is \\\\parsed by String on \\and then on a literal \by the RegEx parser.

+10
source

Eliminate the escape character: "\\"

+4
source

, "\" .

\\ .

0

double\in string

String example = "C:\\Program Files";
0
string = @"c:\inetpub\wwwroot\"

 string = "c:\\inetpub\\wwwroot\\"

in some cases ... I'm not 100% sure, but I think it may be language dependent ... I KNOW "@" works in C #

0
source

You can write:

String newstr = "\\"; 

\ is a special character inside the string used for escaping.

"\"Now it works because it eludes the second ".

To get a literal \, you need to avoid it using \.

0
source

Source: https://habr.com/ru/post/1772494/


All Articles