How can I put an escape character in front of special characters using C #?
buildLetter.Append("</head>").AppendLine();
buildLetter.Append("").AppendLine();
buildLetter.Append("<style type="text/css">").AppendLine();
Suppose the above content is in a file. I want to write a fragment that deletes any line with the empty string "" and places the escape character in front of the middle quotes. The end result will be:
buildLetter.Append("</head>").AppendLine();
buildLetter.Append("<style type=\"text/css\">").AppendLine();
External "...." are not considered special characters. Special characters can be single quote or double quotation mark.
I could run it through the Visual Studio search and replace function. However, in my case i want it to be written in C # or VB.NET
Any help would be appreciated.
, , :
string s = File.ReadAllText("input.txt");
string empty = "buildLetter.Append(\"\").AppendLine();" + Environment.NewLine;
s = s.Replace(empty, "");
s = Regex.Replace(s, @"(?<="").*(?="")",
match => { return match.Value.Replace("\"", "\\\""); }
);
:
buildLetter.Append("</head>").AppendLine();
buildLetter.Append("<style type=\"text/css\">").AppendLine();