Writing “\\” inside a string

Posted by  Babe Zaharias
 1539  View(s)
Rate this:
Hi Developers!

I want to do something like:

string s = "\\blabla";

when you write "\" it means there will only be a single '\'. How do I write the string so there will actually be 2 '\' meaning "\" ?

  1. Re: Writing “\\” inside a string

    Hi Babe!

    This works without a problem:

    string s = "//blabla";
    If you mean the backslash instead, you can use a verbatim string literal (using the @ symbol to avoid processing escape symbols):

    string s = @"\\blabla";
    Alternatively you can escape the escape character itself:

    string s = "\\\\blabla";