【发布时间】:2020-08-23 03:42:39
【问题描述】:
我是 C# 新手,我必须通过 C# 脚本在文本文件中编写 Linux 代码,但在 MyText 文件中写入“到”时遇到问题。
C# 代码在 MyText 字符串中给出错误。
string MyText = "#!/bin/bash\n" +
"_dbInput=/root/input.csv\n" + **(should be "_dbInput="/root/input.csv"\n" +)**
"sleep 0.5\n" +
"_linect_total=$(cat $_dbInput | wc -l)\n" +
"sleep 2\n";
我需要像下面这样的输出
"_dbInput="/root/input.csv"\n" +
"rm –rf /tmp/filename.txt"
需要 " (双引号) 打印在文本文件 MyText.. 需要建议我该如何实现这一目标。
问候,
【问题讨论】:
-
你需要edit你的帖子来包含你现在使用的代码。如果我们看不到它,我们无法调试它为什么不起作用。请参阅minimal reproducible example 了解更多信息。
-
“特殊字符”是双引号,在字符串中处理并不少见。这回答了你的问题了吗? How to add double quotes to a string that is inside a variable? 或 Escape double quotes in string
-
只需在你的字符串中使用 \" 而不是 "
_dbInput=\"/root/input.csv\"
标签: c#