【发布时间】:2021-12-02 20:31:50
【问题描述】:
大家好,我想将我的 CSV 文件(路径)转换为 XML 文件(保存路径)。 在 CSV 文件中有 13 个 headers 元素,我将所有元素放在一个数组字符串中。 我的问题是:我只想将数组的 1、2、3、10、11、12 元素放入 XML 文件中。 我该怎么做?跳过我只跳过第一个,但我如何跳过中间的元素? 非常感谢!!
var lines = File.ReadAllLines(path);
string[] headers;
headers = new string[13] {"PlantNo", "No", "Name", "cod_fatt", "tags_grp", "dos_type", "pervuoti", "cemq_chk", "rapp_ac", "code_01", "unit_01", "peso_01",""};
for (int i = 0; i < headers.Length; i ++)
{
lunghezza = i;
}
var xml = new XElement("DC8_Recipes",
lines.Where((line, lunghezza) => lunghezza > 0).Select(line => new XElement("DC8_Recipes",
line.Split(';').Skip(1).Select((column, lunghezza) => new XAttribute(headers[lunghezza], column)))));
xml.Save(savepath);
【问题讨论】:
-
line.Split(';').Where((v, i) => !(i < 1 || (i > 4 && i < 10)))应该为您提供索引 1-3 和 10-12 处的值 -
是的,是函数!!