views:

59

answers:

1
buildLetter.Append("</head>").AppendLine();
buildLetter.Append("").AppendLine();
buildLetter.Append("<style type="text/css">").AppendLine();

Assume the above contents resides in a file. I want to write a snippet that removes any line which has empty string "" and put escape character before the middle quotations. The final output would be:

buildLetter.Append("</head>").AppendLine();
buildLetter.Append("<style type=\"text/css\">").AppendLine();

The outer " .... " is not considered special chars. The special chars may be single quotation or double quotation.

I could run it via find and replace feature of Visual Studio. However, in my case i want it to be written in c# or VB.NET

Any help will be appreciated.

+3  A: 

Perhaps this does what you want:

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("\"",  "\\\""); }
    );

Result:

buildLetter.Append("</head>").AppendLine();
buildLetter.Append("<style type=\"text/css\">").AppendLine();
Mark Byers
Will try it and let you know...
Beginner_Pal
Worked .................
Beginner_Pal