使用@符号时将\\替换为\

时间:2017-09-05 23:36:54

标签: c# replace

替换文字的问题...用户名为'JoelFarrell'

buildBnBList

任何人都有任何想法?谢谢你的回复

如果我在快速观察中对其进行测试并更改userName = @"WILD\" + userName; // returns "WILD\\JoelFarrell" I only want "WILD\JoelFarrell" so ive tried to replace it userName = userName.Replace("\\", @"\");//this does not work userIdInDNNUsersTable = DbContext.Users.Where(x => x.Username == userName).Count();//returns 0 results because it is searching for 'WILD\\JoelFarrell' where as if it was searching for 'WILD\JoelFarrell' I would get what I am looking for ,则表示无法识别的重新映射序列。但是如果我在db中搜索SQL中的记录

userName = "WILDFIRE\JoelFarrel"

返回我正在查找的结果。那么我如何在代码中得到这个结果呢?

2 个答案:

答案 0 :(得分:2)

实际上

userName = @"WILD\" + userName; // returns "WILD\\JoelFarrell"

返回

WILD\JoelFarrell

只是调试器将其显示为\\(非常无用的恕我直言)

答案 1 :(得分:1)

当您在调试器中查看userName时,您将看到转义版本。按下手表或工具提示旁边的放大镜。这将为您提供非转义版本。