Escape sequence with “\” symbol

前端 未结 4 1470
遥遥无期
遥遥无期 2021-01-07 03:49

i have one string, and i assign the value like,

string str=\"admin\" + @\"\\\" + \"user\";

The output of the \"str\" value comes as

相关标签:
4条回答
  • 2021-01-07 04:26

    The output of the "str" value comes as "admin\\user"

    No, it really doesn't. The string itself will just have a single backslash.

    If you look at it in the debugger you will see the escaping, but that doesn't mean it's part of the string. It's just the debugger representation. Print it to the console, or log etc to see the real value.

    0 讨论(0)
  • 2021-01-07 04:28

    Simply:

    String str = @"admin\user"
    
    0 讨论(0)
  • 2021-01-07 04:32

    I'm sure your string is actually fine.

    I am guessing you are looking at the value in the debugger and seeing \\. This is because the debugger is escaping a single \ to \\ to make it clear to you that this is a slash and not a control code.

    For example, the debugger shows a tab as \t, so in order to show you a slash followed by the letter t it escapes it to \\t.

    If you write this string out to console/log/file, you'll see it is as you expect.

    0 讨论(0)
  • 2021-01-07 04:34

    I don't see where your problem lies... Looks fine to me. - View stuff as the end user, and not in the debugger as Rob suggests.

    enter image description here

    0 讨论(0)
提交回复
热议问题