public void DelimitersCannotBeNull() { using (StringReader reader = new StringReader(string.Empty)) { using (DelimitedFieldParser parser = new DelimitedFieldParser(reader)) { parser.SetDelimiters(null); } } }
public void MultipleDelimiters() { string text = "a bb\tccc\tdddd"; using (StringReader reader = new StringReader(text)) { using (DelimitedFieldParser parser = new DelimitedFieldParser(reader)) { parser.SetDelimiters(' ', '\t'); Assert.AreEqual("a:bb:ccc:dddd", parser.ReadFields().ToString(":")); } } }
public void CanSqueezeDelimiters() { string text = "a bb ccc dddd"; using (StringReader reader = new StringReader(text)) { using (DelimitedFieldParser parser = new DelimitedFieldParser(reader)) { parser.SetDelimiters(' '); parser.SqueezeDelimiters = true; Assert.AreEqual("a:bb:ccc:dddd", parser.ReadFields().ToString(":")); } } }
public void CanParseMultipleFields() { string newLine = "\r\n"; string text = "a;bb;ccc;dddd" + newLine + "111;22;3"; using (StringReader reader = new StringReader(text)) { using (DelimitedFieldParser parser = new DelimitedFieldParser(reader)) { parser.SetDelimiters(';'); Assert.AreEqual("a:bb:ccc:dddd", parser.ReadFields().ToString(":")); Assert.AreEqual("111:22:3", parser.ReadFields().ToString(":")); } } }
public void CanHandleUnixStyleNewLine() { string newLine = "\n"; string text = "a;bb;ccc;dddd" + newLine + "e;ff;ggg;hhhh"; using (StringReader reader = new StringReader(text)) { using (DelimitedFieldParser parser = new DelimitedFieldParser(reader)) { parser.SetDelimiters(';'); Assert.AreEqual("a:bb:ccc:dddd", parser.ReadFields().ToString(":")); Assert.AreEqual("e:ff:ggg:hhhh", parser.ReadFields().ToString(":")); } } }
public void DelimitersTest() { using (StringReader reader = new StringReader(string.Empty)) { using (DelimitedFieldParser parser = new DelimitedFieldParser(reader)) { char[] delimiters = { ',', ';' }; parser.SetDelimiters(delimiters); delimiters[0] = '\t'; Assert.AreNotEqual('\t', parser.GetDelimiters()[0]); } } }
public void CanTrimWhiteSpace() { string newLine = "\r\n"; string text = "a;bb ; ccc; dddd " + newLine; using (StringReader reader = new StringReader(text)) { using (DelimitedFieldParser parser = new DelimitedFieldParser(reader)) { parser.SetDelimiters(';'); parser.TrimWhiteSpace = true; Assert.AreEqual("a:bb:ccc:dddd", parser.ReadFields().ToString(":")); } } }
public void CanSkipCommentedLines() { string newLine = "\r\n"; string text = "#Comment line" + newLine + "a;bb;ccc;dddd"; using (StringReader reader = new StringReader(text)) { using (DelimitedFieldParser parser = new DelimitedFieldParser(reader)) { parser.SetDelimiters(';'); parser.SetCommentTokens("#"); Assert.AreEqual("a:bb:ccc:dddd", parser.ReadFields().ToString(":")); } } }
public void CanReadFromFile() { string textFile = Path.GetTempFileName(); try { using (StreamWriter writer = new StreamWriter(textFile, false)) { writer.WriteLine("a,bb,ccc,dddd"); } using (DelimitedFieldParser parser = new DelimitedFieldParser(textFile)) { parser.SetDelimiters(','); Assert.AreEqual("a:bb:ccc:dddd", parser.ReadFields().ToString(":")); } } finally { File.Delete(textFile); } }