Advertisement
sec_goat

Untitled

Feb 21st, 2013
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.96 KB | None | 0 0
  1.  List<String> malformedLines = new List<string>(); //keep track of all malformed lines in a row and then add them together then write the line
  2.             string line = "";
  3.             using (StreamReader reader = new StreamReader(filepath))
  4.             {
  5.                 using (StreamWriter writer = new StreamWriter(System.Web.HttpContext.Current.Server.MapPath("~/dbfiles/temp.NFPOX")))
  6.                 {
  7.                     while ((line = reader.ReadLine()) != null)
  8.                     {
  9.                         var trimmedLine = line.Trim();
  10.  
  11.                         Match match = startsWith.Match(trimmedLine,);
  12.                         Match matchXML = startsWithXML.Match(trimmedLine);
  13.                         Match matchEnd = endsWith.Match(trimmedLine);
  14.                         Match matchRootStart = startRoot.Match(trimmedLine);
  15.                         Match matchRootEnd = endRoot.Match(trimmedLine);
  16.  
  17.                         if ((matchXML.Success || matchRootStart.Success || matchRootEnd.Success) ||
  18.                             (match.Success && matchEnd.Success))
  19.                         {
  20.                             if(brokenLinesFound > 0)
  21.                             {
  22.                                  brokenLinesFound = 0;
  23.                                  var fixedLine = malformedLines.
  24.                            
  25.                             }
  26.                            
  27.                             writer.WriteLine(line);
  28.                         }
  29.  
  30.                         else if (!match.Success)
  31.                         {
  32.                             brokenLinesFound += 1;
  33.                             found_broken_lines = true;
  34.  
  35.                             if(brokenLinesFound > 0)
  36.                             {
  37.                                 malformedLines.Add(trimmedLine);
  38.                             }
  39.                            
  40.                         }
  41.                        
  42.                     }
  43.                 }
  44.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement