我有一个CSV文件,我需要在C#中打开作为一个顺序文件。它必须由头文件解析。解析CSV数据基于头然后加载到数组
截至目前,我只知道如何将数据文件作为使用C#System.IO库的顺序文件加载到ArrayList结构中。文件中的每一行都必须是单独的记录。这是它:
using System;
using System.IO;
using System.Collections;
namespace FileSearch
{
class Class1
{
static void Main(string[] args)
{
StreamReader objReader = new StreamReader("c:\\Users/Sarah/Desktop/IP4Data.csv"); //open file to read
string sLine = ""; //string variable for data that goes into ArrayList
ArrayList arrText = new ArrayList();
while (sLine != null)
{
sLine = objReader.ReadLine(); //read file one line at a time
if (sLine != null) //if empty, it's null
arrText.Add(sLine);//Add data to Array List
}
objReader.Close(); //end loop
foreach (string sOutput in arrText) //Outputs read data from ArrayList onto screen
Console.WriteLine(sOutput);
Console.ReadLine();
}
}
}
如何解析CSV文件,以便它可以在ArrayList中搜索?
分开你读过如何CSV文件建立?如果是的话,你有理解吗?如果是的话,你开始实施它吗? – 2014-10-29 19:52:45
你使用'ArrayList'而不是'List <>'的任何原因?不是它是无效的,[这只是做它的老方法](http://stackoverflow.com/a/2309699/1765721)。 – 2014-10-29 19:55:18
你需要提供一个CSV样本,并描述你的意思是“searchable”。 – Jonesopolis 2014-10-29 20:04:15