0

I am new to C#, I have to write a Linux code via C# script in a text file, but facing issue in writing " to in MyText file.

C# code gives error in MyText string.

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";

I need output like below

"_dbInput="/root/input.csv"\n" +

"rm –rf /tmp/filename.txt"

Need " (Double-Quote) to printed in text file MyText.. Need suggestion how can I achieve this.

Regards,

khawaja
  • 3
  • 1
  • You need to [edit] your post to include the code you're using now. We can't debug why it's not working if we can't see it. See [mre] for more information. – Ken White May 07 '20 at 18:04
  • The "special character" is a double quote, which is not uncommon to deal with in strings. Does this answer your question? [How to add double quotes to a string that is inside a variable?](https://stackoverflow.com/questions/3905946/how-to-add-double-quotes-to-a-string-that-is-inside-a-variable) or [Escape double quotes in string](https://stackoverflow.com/q/14480724/150605) – Lance U. Matthews May 07 '20 at 18:11
  • 1
    Just use \" in your string instead " `_dbInput=\"/root/input.csv\"` – Denis Stukalov May 07 '20 at 18:31

1 Answers1

1

You need to use the \" \" pair. For example:

Console.WriteLine("There are \"double quotes\" in this sentence  ");

The output is:

There are "double quotes" in this sentence

The console is just one standard output, the same line in StreamWriter.WriteLine would print the same thing in a file.

DrMaxB
  • 540
  • 1
  • 3
  • 13