当前位置: 代码迷 >> ASP.NET >> 怎么把字符串中的"\\"替换为"\"(string.replace("\\""\")行不通)
  详细解决方案

怎么把字符串中的"\\"替换为"\"(string.replace("\\""\")行不通)

热度:7117   发布时间:2013-02-26 00:00:00.0
如何把字符串中的"\\"替换为"\"(string.replace("\\","\")行不通)
如何把字符串中的 "\\ "替换为 "\ "(string.replace( "\\ ", "\ ")行不通)

------解决方案--------------------------------------------------------
string.replace( "\\\\ ", "\\ ")
------解决方案--------------------------------------------------------
str = str.Replace( "\\\\ ", "\\ ");
------解决方案--------------------------------------------------------
str = str.Replace( "\\\\ ", "\\ ");

------解决方案--------------------------------------------------------
str = str.Replace(@ "\\ ",@ "\ ");
------解决方案--------------------------------------------------------
是注意转义字符.
------解决方案--------------------------------------------------------
str = str.Replace( "\\\\ ", "\\ ");
------解决方案--------------------------------------------------------
同意楼上的解释, " "中出现\是转义字符的标志,所以第二个才是真正的\,要弄出1个\就要写2个\,明白了吧?
------解决方案--------------------------------------------------------
str = str.Replace(@ "\\ ",@ "\ ");

------解决方案--------------------------------------------------------
up viena(维也纳N02) shalen520(Love will keep us alive)
------解决方案--------------------------------------------------------
str = str.Replace(@ "\\ ",@ "\ ");
  相关解决方案