如何让readfield读取下一个字段
how to make readfield read next field
我的 csv 文件包含 8 列和 300k rows.Here 是我的 csv 文件的示例
"0195153448";"Classical Mythology";"Mark P. O. Morford";"2002";"Oxford University Press";"http://images.amazon.com/images/P/0195153448.01.THUMBZZZ.jpg";"http://images.amazon.com/images/P/0195153448.01.MZZZZZZZ.jpg";"http://images.amazon.com/images/P/0195153448.01.LZZZZZZZ.jpg"
"0002005018";"Clara Callan";"Richard Bruce Wright";"2001";"HarperFlamingo Canada";"http://images.amazon.com/images/P/0002005018.01.THUMBZZZ.jpg";"http://images.amazon.com/images/P/0002005018.01.MZZZZZZZ.jpg";"http://images.amazon.com/images/P/0002005018.01.LZZZZZZZ.jpg"
现在我有了这个阅读代码
string path = @"C:\Users\SEMRUK\Desktop\exceller\kitaplik.csv";
public DataTable GetDataTabletFromCSVFile(string PathFile)
{
DataTable csvData = new DataTable();
TextFieldParser csvReader = new TextFieldParser(PathFile);
csvReader.SetDelimiters(new string[] {";"});
csvReader.HasFieldsEnclosedInQuotes = true;
string[] colFields = csvReader.ReadFields();
foreach (string column in colFields)
{
DataColumn datecolumn = new DataColumn(column);
datecolumn.AllowDBNull = true;
csvData.Columns.Add(datecolumn);
}
string[] fieldData = csvReader.ReadFields();
while (!csvReader.EndOfData)
{
for (int i = 0; i < fieldData.Length; i++)
{
if (fieldData[i] == "")
{
fieldData[i] = null;
}
MessageBox.Show(fieldData[i]);
}
csvData.Rows.Add(fieldData);
}
return csvData;
}
这样我可以阅读前 8 个 rows.But 我无法在 that.It 之后阅读任何内容只是先阅读 8.How 我可以告诉代码它应该在 tab [ 之后阅读吗=30=] 尝试将 \t 添加到 setdelimiters 但没有 work.Any 建议?
static void Main(string[] args)
{
string path = "your_file_path";
string text = System.IO.File.ReadAllText(path);
string[] parsedText= text.Split(';');
foreach (var item in parsedText)
{
//do some
}
}
我的 csv 文件包含 8 列和 300k rows.Here 是我的 csv 文件的示例
"0195153448";"Classical Mythology";"Mark P. O. Morford";"2002";"Oxford University Press";"http://images.amazon.com/images/P/0195153448.01.THUMBZZZ.jpg";"http://images.amazon.com/images/P/0195153448.01.MZZZZZZZ.jpg";"http://images.amazon.com/images/P/0195153448.01.LZZZZZZZ.jpg"
"0002005018";"Clara Callan";"Richard Bruce Wright";"2001";"HarperFlamingo Canada";"http://images.amazon.com/images/P/0002005018.01.THUMBZZZ.jpg";"http://images.amazon.com/images/P/0002005018.01.MZZZZZZZ.jpg";"http://images.amazon.com/images/P/0002005018.01.LZZZZZZZ.jpg"
现在我有了这个阅读代码
string path = @"C:\Users\SEMRUK\Desktop\exceller\kitaplik.csv";
public DataTable GetDataTabletFromCSVFile(string PathFile)
{
DataTable csvData = new DataTable();
TextFieldParser csvReader = new TextFieldParser(PathFile);
csvReader.SetDelimiters(new string[] {";"});
csvReader.HasFieldsEnclosedInQuotes = true;
string[] colFields = csvReader.ReadFields();
foreach (string column in colFields)
{
DataColumn datecolumn = new DataColumn(column);
datecolumn.AllowDBNull = true;
csvData.Columns.Add(datecolumn);
}
string[] fieldData = csvReader.ReadFields();
while (!csvReader.EndOfData)
{
for (int i = 0; i < fieldData.Length; i++)
{
if (fieldData[i] == "")
{
fieldData[i] = null;
}
MessageBox.Show(fieldData[i]);
}
csvData.Rows.Add(fieldData);
}
return csvData;
}
这样我可以阅读前 8 个 rows.But 我无法在 that.It 之后阅读任何内容只是先阅读 8.How 我可以告诉代码它应该在 tab [ 之后阅读吗=30=] 尝试将 \t 添加到 setdelimiters 但没有 work.Any 建议?
static void Main(string[] args)
{
string path = "your_file_path";
string text = System.IO.File.ReadAllText(path);
string[] parsedText= text.Split(';');
foreach (var item in parsedText)
{
//do some
}
}