Train
Lifer
did this while on a con call. 20-25 lines, depending on how you count them
NOT TESTED
NOT TESTED
Code:
using System;
using System.Collections.Generic;
using System.IO;
namespace Cad_Converter
{
class Program
{
static void Main(string[] args)
{
// the source file path
string sourceFile = args[0];
// destination file path
string destFile = args[1];
// List of started "codes"
var codes = new List<string>();
string previousCode = "";
foreach (var s in File.ReadAllLines(sourceFile))
{
var code = ExtractCode(s);
if (code == previousCode)
{
File.AppendAllText(destFile, s + nl);
}
else
{
var txt = "END" + nl;
if (codes.Contains(code))
{
txt += "CONT ";
}
else
{
txt += "BEG ";
codes.Add(code);
}
txt += code + nl + s + nl;
File.AppendAllText(destFile, txt);
previousCode = code;
}
}
// Add another end at the end
File.AppendAllText(destFile, "END");
}
private static string nl = Environment.NewLine;
static string ExtractCode(string line)
{
// Grab what is between the quotes
int start = line.IndexOf('"')+1;
int len = line.Length - start - 1;
return line.Substring(start, len);
}
}
}