如何在单反斜杠中替换双反斜杠 [英] How to replace Double Backslash in single backslash

查看:158
本文介绍了如何在单反斜杠中替换双反斜杠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在尝试将双反斜杠替换为单反斜杠.但无法正确进行.

假设我的字符串是

Hi,
i am trying to replace double backslash into single backslash.but its not happenuig correctly.

Suppose my string is

string str1 = "123\\456\\789\\10";
str1 = str1.Replace(@"\\", @"\");
Response.Write(str1);


它显示正确的123 \ 456 \ 789 \ 10,但在调试模式下的值仍保留为双反斜杠格式
而且我需要单反斜杠中的值.
请回复.
预先表示感谢....


it display 123\456\789\10 its correct but on the debug mode value is remain in double backslash format
and i need the value in single backslash.
please reply.
Thannks in advance....

推荐答案

"\"是C#中的转义字符. C#通常使用"\\"表示"\".因此,这不是问题.
"\" is a escape character in C#. C# usually uses "\\" to denote "\". So, it is not a problem.


我假设您正在研究变量(在Visual Studio中).
我相信(不确定)Visual Studio将显示原始数据,并且会将换行符显示为"\ n",因此将斜杠显示为"\\".
I assume you''re looking into the variable (in Visual Studio).
I believe (not sure) visual studio displays the raw data and would displays a newline as ''\n'', thus display a slash as ''\\''.
Makes sense, not?


它是单反斜杠格式.
当您在调试器中查看任何字符串时,它会以适当的转义符显示它们:"\ n","\ t"和"\\"分别代表换行符,制表符和单个反斜杠.

如果您考虑一下,这是有道理的:如果没有考虑,您将无法分辨出两者之间的任何区别
It is in single backslash format.
When you look at any string in the debugger, it shows them with appropriate escape characters: "\n", "\t" and "\\" for newline, tab and a single backslash respectively.

If you think about it, it makes sense: if it didn''t you would not be able to tell any difference between
"Hello\nThere"

单词之间有反斜杠和小写字母"n"的单行,

A single line with a backslash and a lower case ''n'' between the words, and

"Hello\nThere"

两行,"Hello"之一和"There"之一
在调试器中,这些将显示为:

Two lines, one of "Hello" and one of "There"
In the debugger, these would be shown as:

"Hello\\nThere"


"Hello\nThere"

分别.


这篇关于如何在单反斜杠中替换双反斜杠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆