本文整理汇总了C#中CsvRecordReader.Read方法的典型用法代码示例。如果您正苦于以下问题:C# CsvRecordReader.Read方法的具体用法?C# CsvRecordReader.Read怎么用?C# CsvRecordReader.Read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CsvRecordReader
的用法示例。
在下文中一共展示了CsvRecordReader.Read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ArgumentTestIndexer1
public void ArgumentTestIndexer1()
{
using (CsvRecordReader csv = new CsvRecordReader(new StringReader(CsvReaderSampleData.SampleData1), false))
{
record = csv.Read();
string s = record[-1];
}
}
示例2: SkipEmptyLinesTest2
public void SkipEmptyLinesTest2()
{
using (CsvRecordReader csv = new CsvRecordReader(new StringReader("00\n\n10"), false))
{
csv.SkipEmptyLines = true;
Assert.AreEqual(1, csv.FieldCount);
record = csv.Read(); Assert.NotNull(record);
Assert.AreEqual("00", record[0]);
record = csv.Read(); Assert.NotNull(record);
Assert.AreEqual("10", record[0]);
Assert.IsNull(csv.Read());
}
}
示例3: ParsingTest7
public void ParsingTest7()
{
using (CsvRecordReader csv = new CsvRecordReader(new System.IO.StringReader("\r\n1\r\n"), false))
{
record = csv.Read(); Assert.NotNull(record);
Assert.AreEqual(',', csv.Delimiter);
Assert.AreEqual(0, csv.CurrentRecordIndex);
Assert.AreEqual(1, csv.FieldCount);
Assert.AreEqual("1", record[0]);
Assert.IsNull(csv.Read());
}
}
示例4: ArgumentTestIndexer3
public void ArgumentTestIndexer3()
{
using (CsvRecordReader csv = new CsvRecordReader(new StringReader(CsvReaderSampleData.SampleData1), false))
{
string s = csv.Read()["asdf"];
}
}
示例5: ParsingTest40
public void ParsingTest40()
{
using (CsvRecordReader csv = new CsvRecordReader(new StringReader("\"00\",\n\"10\","), false))
{
Assert.AreEqual(2, csv.FieldCount);
record = csv.Read(); Assert.NotNull(record);
Assert.AreEqual("00", record[0]);
Assert.AreEqual(string.Empty, record[1]);
record = csv.Read(); Assert.NotNull(record);
Assert.AreEqual("10", record[0]);
Assert.AreEqual(string.Empty, record[1]);
Assert.IsNull(csv.Read());
}
}
示例6: ParsingTest39
public void ParsingTest39()
{
using (CsvRecordReader csv = new CsvRecordReader(new StringReader("00,01, \n10,11, "), false, CsvReader.DefaultDelimiter, CsvReader.DefaultQuote, CsvReader.DefaultEscape, CsvReader.DefaultComment, ValueTrimmingOptions.UnquotedOnly, 1))
{
int fieldCount = csv.FieldCount;
record = csv.Read(); Assert.NotNull(record);
Assert.AreEqual("00", record[0]);
Assert.AreEqual("01", record[1]);
Assert.AreEqual("", record[2]);
record = csv.Read(); Assert.NotNull(record);
Assert.AreEqual("10", record[0]);
Assert.AreEqual("11", record[1]);
Assert.AreEqual("", record[2]);
Assert.IsNull(csv.Read());
}
}
示例7: ParsingTest35
public void ParsingTest35()
{
using (CsvRecordReader csv = new CsvRecordReader(new StringReader("\t"), false, '\t'))
{
Assert.AreEqual(2, csv.FieldCount);
record = csv.Read(); Assert.NotNull(record);
Assert.AreEqual(string.Empty, record[0]);
Assert.AreEqual(string.Empty, record[1]);
Assert.IsNull(csv.Read());
}
}
示例8: ParsingTest33
public void ParsingTest33()
{
const string data = "\"double\\\\\\\\double backslash\"";
using (CsvRecordReader csv = new CsvRecordReader(new System.IO.StringReader(data), false, ',', '\"', '\\', '#', ValueTrimmingOptions.None))
{
record = csv.Read(); Assert.NotNull(record);
Assert.AreEqual("double\\\\double backslash", record[0]);
Assert.AreEqual(0, csv.CurrentRecordIndex);
Assert.AreEqual(1, csv.FieldCount);
Assert.IsNull(csv.Read());
}
}
示例9: ParsingTest19
public void ParsingTest19()
{
string data = String.Empty;
using (CsvRecordReader csv = new CsvRecordReader(new System.IO.StringReader(data), false))
{
Assert.IsNull(csv.Read());
}
}
示例10: ParsingTest16
public void ParsingTest16()
{
const string data = "1\r2\n";
using (CsvRecordReader csv = new CsvRecordReader(new System.IO.StringReader(data), false, '\r', '"', '\"', '#', ValueTrimmingOptions.UnquotedOnly))
{
record = csv.Read(); Assert.NotNull(record);
Assert.AreEqual("1", record[0]);
Assert.AreEqual("2", record[1]);
Assert.AreEqual(0, csv.CurrentRecordIndex);
Assert.AreEqual(2, csv.FieldCount);
Assert.IsNull(csv.Read());
}
}
示例11: GetFieldHeaders_WithEmptyHeaderNames
public void GetFieldHeaders_WithEmptyHeaderNames(string defaultHeaderName)
{
if (defaultHeaderName == null)
defaultHeaderName = "Column";
using (var csv = new CsvRecordReader(new StringReader(", ,,aaa,\" \",,,"), true))
{
csv.DefaultHeaderName = defaultHeaderName;
Assert.IsNull(csv.Read());
Assert.AreEqual(8, csv.FieldCount);
var headers = csv.GetFieldHeaders();
Assert.AreEqual(csv.FieldCount, headers.Length);
Assert.AreEqual("aaa", headers[3]);
foreach (var index in new int[] { 0, 1, 2, 4, 5, 6, 7 })
Assert.AreEqual(defaultHeaderName + index.ToString(), headers[index]);
}
}
示例12: ArgumentTestIndexer9
public void ArgumentTestIndexer9()
{
using (CsvRecordReader csv = new CsvRecordReader(new StringReader(CsvReaderSampleData.SampleData1), true))
{
var record = csv.Read();
string s = record["asdf"];
}
}
示例13: UnicodeParsingTest3
public void UnicodeParsingTest3()
{
byte[] buffer;
string test = "München";
using (MemoryStream stream = new MemoryStream())
{
using (TextWriter writer = new StreamWriter(stream, Encoding.Unicode))
{
writer.Write(test);
}
buffer = stream.ToArray();
}
using (CsvRecordReader csv = new CsvRecordReader(new StreamReader(new MemoryStream(buffer), Encoding.Unicode, false), false))
{
record = csv.Read(); Assert.NotNull(record);
Assert.AreEqual(test, record[0]);
Assert.IsNull(csv.Read());
}
}
示例14: UnicodeParsingTest1
public void UnicodeParsingTest1()
{
// control characters and comma are skipped
char[] raw = new char[65536 - 13];
for (int i = 0; i < raw.Length; i++)
raw[i] = (char)(i + 14);
raw[44 - 14] = ' '; // skip comma
string data = new string(raw);
using (CsvRecordReader csv = new CsvRecordReader(new StringReader(data), false))
{
record = csv.Read(); Assert.NotNull(record);
Assert.AreEqual(data, record[0]);
Assert.IsNull(csv.Read());
}
}
示例15: ParsingTest2
public void ParsingTest2()
{
// ["Bob said, ""Hey!""",2, 3 ]
const string data = "\"Bob said, \"\"Hey!\"\"\",2, 3 ";
using (CsvRecordReader csv = new CsvRecordReader(new StringReader(data), false))
{
CsvRecord record;
record = csv.Read();
Assert.NotNull(record);
Assert.AreEqual(@"Bob said, ""Hey!""", record[0]);
Assert.AreEqual("2", record[1]);
Assert.AreEqual("3", record[2]);
Assert.IsNull(csv.Read());
}
using (CsvRecordReader csv = new CsvRecordReader(new StringReader(data), false, ',', '"', '"', '#', ValueTrimmingOptions.None))
{
record = csv.Read(); Assert.NotNull(record);
Assert.AreEqual(@"Bob said, ""Hey!""", record[0]);
Assert.AreEqual("2", record[1]);
Assert.AreEqual(" 3 ", record[2]);
Assert.IsNull(csv.Read());
}
}