【发布时间】:2014-04-19 05:43:49
【问题描述】:
只是尝试 C# 来制作一个加载 csv 文件的按钮来验证它们并解析它们:
protected void Upload_Btn_Click(object sender, EventArgs e)
{
string test = PNLdataLoader.FileName;
//checks if file is csv
Regex regex = new Regex("*.csv");
Match match = regex.Match(test);
if (match.Success)
{
string CSVFileAsString = System.Text.Encoding.ASCII.GetString(PNLdataLoader.FileBytes);
System.IO.MemoryStream MS = new System.IO.MemoryStream(PNLdataLoader.FileBytes);
System.IO.StreamReader SR = new System.IO.StreamReader(MS);
//Store each line in CSVlines array of strings
string[] CSVLines = new string[0];
while (!SR.EndOfStream)
{
System.Array.Resize(ref CSVLines, CSVLines.Length + 1);
CSVLines[CSVLines.Length - 1] = SR.ReadLine();
}
}
到目前为止,我已经将这些行存储在 CSVLines 中,但我不确定正则表达式有什么问题。有没有更有效的方法来做到这一点?
【问题讨论】:
-
我没有看到二维数组,是不是漏掉了什么?
-
@MarkF 我还没有进入那部分,但仍在查看有关如何操作的文档。