WRITING “\\” INSIDE A STRING

Babe Zaharias

Total Post:19

Points:133
Posted by  Babe Zaharias
C# 
C#
 1084  View(s)
Ratings:
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. AVADHESH PATEL

    Post:604

    Points:4228
    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";

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!