使用转义字符格式化字符串

时间:2014-08-21 02:34:47

标签: c#

我花了这么长时间尝试在c#中对其进行格式化,并尝试了多种不同的组合(我不会列出它们,因为它太多了!),但还没有成功。有人可以帮我一把吗?

我想要的结果:

  

/ LOGGER" \" \ server \ c $ \ Packages Log \ SSISErrors.txt \""

我试图使用字符串构建器,但这无法使工作更轻松:

string path = String.Format(@"\\{0}\c$\Packages Log\", Environment.MachineName);
StringBuilder buildLogcmd = new StringBuilder();
                    buildLogcmd.Append("/LOGGER ");
                    buildLogcmd.Append(String.Format("\"\\\" \\{0}\\SSISErrors.txt\\ \"\"", path));

当前输出:

  

/ LOGGER" \" \\\ server \ c $ \ Packages Log \\ SSISErrors.txt \

2 个答案:

答案 0 :(得分:0)

        string path = String.Format(@"""\""\{0}\c$\Packages Log\", Environment.MachineName);
        StringBuilder buildLogcmd = new StringBuilder();
        buildLogcmd.Append("/LOGGER ");
        buildLogcmd.Append(String.Format(@"{0}SSISErrors.txt\""""", path));

答案 1 :(得分:0)

string path = String.Format(@"{0}\c$\Packages Log", Environment.MachineName);
StringBuilder buildLogcmd = new StringBuilder();
                    buildLogcmd.Append("/LOGGER ");
                    buildLogcmd.Append(String.Format("\"\\\"\\{0}\\SSISErrors.txt\\\"\"", path));