本文介绍了在运行时用/替换//的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在路径中得到//我想要单个/.每当我调试它时,我都会在运行时得到//.我也使用了替换方法.但它不起作用.我的代码是

i'm getting // in path i want single /. whenever i'm debugging it i'm getting // at run time. i have also used replace method. but it isn't working. My code is

 string inputFile =
 Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName +
 "\\InputFiles\\" + config.country + ".txt";
  inputFile = inputFile.Replace(@"\\", @"\");

推荐答案

您仅在调试模式下获得 \\,因为在可视化字符串文字时,调试器正在重新转义它以用于可视化目的,但是当使用它时,字符串文字将只包含一个 \.

You're getting \\ only in debug mode, because when visualizing the string literal the debugger is re-escaping it for the visualization purposes, however when operating with it, the string literal will contain only a single \.

这篇关于在运行时用/替换//的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 01:25