本文整理汇总了C#中CsvReader.Next方法的典型用法代码示例。如果您正苦于以下问题:C# CsvReader.Next方法的具体用法?C# CsvReader.Next怎么用?C# CsvReader.Next使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CsvReader
的用法示例。
在下文中一共展示了CsvReader.Next方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CsvRecordIterator
public CsvRecordIterator(CsvDataSource datasource, CsvReader reader)
{
_reader = reader;
_builder = new RecordBuilder(datasource);
// index here is random 0-n. index[0] gives the column no in the CSV
// file, while colname[0] gives the corresponding column name.
int columnSize = datasource.GetColumns().Count;
_index = new int[columnSize];
_column = new Column[columnSize];
// skip the required number of lines before getting to the data
for (int ix = 0; ix < datasource.SkipLines; ix++)
{
_reader.Next();
}
// learn column indexes from header line (if there is one)
String[] header;
if (datasource.HasHeader)
{
header = _reader.Next();
}
else
{
// find highest column number
int high = datasource.GetColumns().Select(c => Int32.Parse(c.GetName())).Concat(new[] {0}).Max();
// build corresponding index
header = new string[high];
for (int ix = 0; ix < high; ix++)
{
header[ix] = "" + (ix + 1);
}
}
// build the 'index' and 'column' indexes
int count = 0;
foreach (var column in datasource.GetColumns())
{
for (int ix = 0; ix < header.Length; ix++)
{
if (header[ix].Equals(column.GetName()))
{
_index[count] = ix;
_column[count++] = column;
break;
}
}
}
FindNextRecord();
}
示例2: SetMappingFile
public void SetMappingFile(string filename)
{
_mapping = new Dictionary<string, string>();
//TODO: Fix character encoding?
try
{
var csv = new CsvReader(new StreamReader(filename));
String[] row = csv.Next();
while (row != null)
{
_mapping.Add(row[0], row[1]);
row = csv.Next();
}
csv.Close();
}
catch (System.Exception ex)
{
logger.Error("Error settings mapping file: {0}", ex.Message);
}
}