Backslash Escape Sequence displaying both backslashes

隐身守侯 提交于 2019-12-01 13:11:04

问题


I currently have a string like this:

string login = "DOMAIN\" + userID

Obviously this does not work as I need the backslash escape sequence, right?

string login = "DOMAIN\\" + userID

This displays DOMAIN\\jcwhisman with 2 backslashes?

I have tried all of these in hopes that something will work. While these don't all display 3 slashes, none of them display what I need:

  • string login = @"DOMAIN\" + userID

  • string login = @"DOMAIN\\" + userID

  • string login = "DOMAIN\\" + userID

  • string login = "DOMAIN\" + userID

I know some of those don't seem logical, but I have just been trying everything I can.

I need it to display as DOMAIN\jcwhisman


回答1:


Your two ways are correct and should give you exactly what you want:

  1. string login = @"DOMAIN\" + userID

  2. string login = "DOMAIN\\" + userID

Just make sure that you don't have a backslash at the beginning of your userID.



来源:https://stackoverflow.com/questions/22823853/backslash-escape-sequence-displaying-both-backslashes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!