//File; //Purpose; Creates a text file, or adds line to // an existing file // Fields of each line are separated by '~' // Open a text file // read all the line of the file // split the lines into fields // close the file using System; using System.IO; using System.Linq; using System.Collections.Generic; class Test { public static void Main() { string path = @"MyTest2.txt"; // This text is added only once to the file. if (!File.Exists(path)) { // Create a file to write to. string[] createText = { "L1-Field1~L1-Field2~L1-Field3", "L2-Field1~L2-Field2~L2-Field3", "L3-Field1~L3-Field2~L3-Field3", "L4-Field1~L4-Field2~L4-Field3" }; File.WriteAllLines(path, createText); } // This text is always added, making the file longer over time // if it is not deleted. string appendText = "Ln-Field1~Ln-Field2~Ln-Field3" + Environment.NewLine; File.AppendAllText(path, appendText); var contents = File.ReadAllText(path).Split('\n'); var csv = from line in contents select line.Split('~').ToArray(); var column1 = new List(); var column2 = new List(); using (var rd = new StreamReader(path)) { while (!rd.EndOfStream) { var splits = rd.ReadLine().Split('~'); column1.Add(splits[0]); column2.Add(splits[1]); } } // print column1 Console.WriteLine("Column 1:"); foreach (var element in column1) Console.WriteLine(element); // print column2 Console.WriteLine("Column 2:"); foreach (var element in column2) Console.WriteLine(element); } }