Exemple #1
0
        static void Main(string[] args)
        {
            if (args.Length != 2 && args.Length != 0)
            {
                Console.WriteLine("need two parameters: file name to parse, file name to export");
                return;
            }
            string inputFilePath = "input.txt";
            string exportFilePath = "output.txt";

            if (args.Length == 2)
            {
                inputFilePath = args[0];
                exportFilePath = args[1];
            }

            if (!File.Exists(inputFilePath))
            {
                Console.WriteLine("{0} (input file) doesn't exist", inputFilePath);
            }

            string inputString;
            using (var reader = new StreamReader(inputFilePath))
            {
                inputString = reader.ReadToEnd();
            }
            var parser = new CsvParser();
            IList<IList<string>> parsedValues = parser.Parse(inputString);
            string outputString = parser.PrepForExport(parsedValues);
            using (var writer = new StreamWriter(exportFilePath))
            {
                writer.Write(outputString);
            }
        }
Exemple #2
0
 public void PrepForExportTest()
 {
     IList<IList<string>> testValues = new List<IList<string>>
                                           {new List<string> {"abc", "42"},
                                            new List<string> {"34", "def"}};
     var parser = new CsvParser();
     string outputString = parser.PrepForExport(testValues);
     Assert.That(outputString, Is.EqualTo("[abc] [42]\n[34] [def]"));
 }