Unrecognized Escape Sequence for Path String Containing Backslashes

Unrecognized escape sequence for path string containing backslashes

You can either use a double backslash each time

string foo = "D:\\Projects\\Some\\Kind\\Of\\Pathproblem\\wuhoo.xml";

or use the @ symbol

string foo = @"D:\Projects\Some\Kind\Of\Pathproblem\wuhoo.xml";

parsing '\L' - Unrecognized escape sequence

You need two backslashes to get the correct regex string if you want to match the literal string "\L". Otherwise, the regex engine is going to try to parse "\L" as an escape sequence, as your error is showing. Since you want to escape the backslash for matching literally, you can either enter two escaped backslashes, like so:

bool result = Act("\\\\L", line);

Or you can use a verbatim string

bool result = Act(@"\\L", line);

C# Regex Issue unrecognized escape sequence

Use @ to make the strings no longer use the escape character \:

string regexPattern1 = @"^(\d{3}\.){2}\d{4}$";
string regexPattern2 = @"^((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}$";

As a side note, I think you want the two ifs at the end to be a single if with an or (||) between the two conditions.

C# Unrecognized escape sequence

Use "" to escape quotations when using the @ literal.

Unrecognized escape sequence when using a path as a SQL parameter

Since backslash is considered as a special character(escape), it's causing the issue. Use / or \\ in the path as:

      c:/foldername/subfoldername
c:\\foldername\\subfoldername

OR as you said, use @ in the front as :

     @"c:\foldername\subfoldername"

EDIT: For Javascript, I will simply replace the \ to / as below:

     path = path.split("\\").join("/");

C# Unrecognized escape sequence

Use "" to escape quotations when using the @ literal.



Related Topics



Leave a reply



Submit