CSV到XML如何忽略CSV中的第一行 [英] CSV to XML how to ignore the first line in the CSV
本文介绍了CSV到XML如何忽略CSV中的第一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,
我正在尝试将CSV文件解析为XML。我可以将数据放入Xelements但我想忽略第一行只是标题。
这里是我的代码和csv内容
var statesFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri(" ms-appx:///DataModel\\ Gtfs \\agency.txt"));
StreamReader reader = new StreamReader(await statesFile.OpenStreamForReadAsync());
var list = new List< string>();
using(var r = new StreamReader(await statesFile.OpenStreamForReadAsync()))
{
string line;
while((line = await r.ReadLineAsync())!= null)
{
list.Add(line);
}
};
string [] result = list.ToArray();
XElement cust = new XElement(" Root",from str in result
let fields = str.ToString()。Split(',')
select new XElement(" Agency" ,fields [0]));
返回cust.ToString();
}
解决方案
< blockquote>
您好,
在迭代到while循环之前,您可以进行readline调用,以读取第一行。
如果回答您的问题,请标记答案
Hello,
I am trying to parse the CSV file to XML. I can get the data into Xelements but I want to ignore the first line that is only titles.
here is my code and csv content
var statesFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///DataModel\\Gtfs\\agency.txt")); StreamReader reader = new StreamReader(await statesFile.OpenStreamForReadAsync()); var list = new List<string>(); using (var r = new StreamReader(await statesFile.OpenStreamForReadAsync())) { string line; while ((line = await r.ReadLineAsync()) != null ) { list.Add(line); } }; string[] result = list.ToArray(); XElement cust = new XElement("Root", from str in result let fields = str.ToString().Split(',') select new XElement("Agency", fields[0])); return cust.ToString(); }
解决方案
Hello,
Before you iterate into the while cycle, you can make a readline call, to read the first line.
Mark as an answer if it respond to your question
这篇关于CSV到XML如何忽略CSV中的第一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文