public void CanReadTypedFields() { string text = "01732Juan Perez 0100.0011/05/2002"; using (StringReader reader = new StringReader(text)) { using (FixedWidthFieldParser parser = new FixedWidthFieldParser(reader)) { parser.SetFieldWidths(5, 15, 7, 10); parser.TrimWhiteSpace = true; TextFields fields = parser.ReadFields(); Assert.AreEqual(1732, fields.GetInt32(0)); Assert.AreEqual("Juan Perez", fields.GetString(1)); Assert.AreEqual(100.0f, fields.GetSingle(2)); Assert.AreEqual(new DateTime(2002, 11, 05), fields.GetDateTime(3)); } } }
public void FieldsTypes() { string text = "01732:Juan Perez:0100.00:11/05/2002"; TextFields fields = new TextFields(text.Split(':')); Assert.AreEqual("01732", fields[0]); Assert.AreEqual(1732, fields.GetInt16(0)); Assert.AreEqual(1732, fields.GetInt32(0)); Assert.AreEqual(1732, fields.GetInt64(0)); Assert.AreEqual("Juan Perez", fields.GetString(1)); Assert.AreEqual("0100.00", fields[2]); Assert.AreEqual(100.00f, fields.GetSingle(2)); Assert.AreEqual(100.00f, fields.GetDouble(2)); Assert.AreEqual("11/05/2002", fields[3]); Assert.AreEqual(new DateTime(2002, 11, 05), fields.GetDateTime(3)); }