Python raw string "r" flag equivalent in C# [duplicate]
Asked Answered
L

1

9

I am trying to give the file path in C# which contains special/escape characters. I am new to C#. please help me in defining the file path as raw string literals.

Following is path (\t has spl meaning):

IE_DRIVER_PATH = "C:\software\selenium\temp\drivers\64"

In python we use it as follows (using r - to treat it as raw stiring):

IE_DRIVER_PATH = r"C:\software\selenium\temp\drivers\64"

similarly, In java, we use double slashes.

please help me in defining the same in C#. As of now, I am getting the error which says that file does not exist, though the file is present in the folder.

Loosetongued answered 28/12, 2016 at 9:49 Comment(1)
@tigerhawkt3, as you mentioned, it is indeed duplicate, but I only got to know once you shared the link to the original question as I couldn't find it before I posted this question. I searched with keyword C#, raw strings but I didn't find the question and I am not aware of the terminology verbatim. so, it is just another way of finding what I want from existing python knowledge :).Loosetongued
M
20

In C#, you can either use double slashes (like in Java), or you can use @ instead of r to create a verbatim string literal:

string IE_DRIVER_PATH = @"C:\software\selenium\temp\drivers\64";
Malleus answered 28/12, 2016 at 9:51 Comment(1)
C#11 introduced the real """raw "string" literal""" which is far better than the @"verbatim string literal"Obliquity

© 2022 - 2024 — McMap. All rights reserved.