【发布时间】:2014-12-12 10:02:59
【问题描述】:
我目前正在尝试合并 .csv 文件中的一些行。该文件遵循由“,”分隔的特定格式,最后一个元素使用 \n ascii 代码。这意味着最后一个元素被放到一个新行上,我返回一个只有一个元素的数组。我希望将此元素与其上方的行合并。
所以我的台词是:
192.168.60.24, ACD_test1,86.33352, 07/12/2014 13:33:13, False, Annotated, True,"Attribute1
Attribute 2
Attribute 3"
192.168.60.24, ACD_test1,87.33352, 07/12/2014 13:33:13, False, Annotated, True
是否可以将新的行属性与上面的行合并/加入?
我的代码如下所示:
var reader = new StreamReader(File.OpenRead(@path));
string line1 = reader.ReadLine();
if (line1.Contains("Server, Tagname, Value, Timestamp, Questionable, Annotated, Substituted"))
{
while (!reader.EndOfStream)
{
List<string> listPointValue = new List<string>();
var line = reader.ReadLine();
var values = line.Split(',');
if (values.Count() < 2)
{
//*****Trying to Add Attribute to listPointValue.ElememtAt(0) here******
}
else
{
foreach (string value in values)
{
listPointValue.Add(value);
}
allValues.Add(listPointValue);
}
}
// allValues.RemoveAt(0);
return allValues;
}
【问题讨论】:
标签: c# csv streamreader