gpt4 book ai didi

C#从csv中提取数据

转载 作者:太空宇宙 更新时间:2023-11-03 18:51:20 24 4
gpt4 key购买 nike

我有一个这样的 CSV 文件:

field1,field2,field3,field4,...,fieldN
1,2,3,,...,N

我想准确提取第二行的第 14 条记录。我试过这段代码:

string nomeFile = "externalSourceMsg " + this.DataSource.CodSorgEst + this.DataSource.CodIdSorgEst + ".csv";
string content = "Field1,Field2,Field3,Field4,Field5,Field6,Field7" + Environment.NewLine;
content += externalMessage.ToString();
content = content.Replace(',', ';');

int i = 0;
while (content){
int field;
if(i++ == 13)
field = content+i;
}

但它不起作用。我做错了什么?

最佳答案

拆分字符串,您可以通过索引访问字段。

 string nomeFile = "externalSourceMsg " + this.DataSource.CodSorgEst + this.DataSource.CodIdSorgEst + ".csv";
string content = "Field1,Field2,Field3,Field4,Field5,Field6,Field7" + Environment.NewLine;
content += externalMessage.ToString();
content = content.Replace(',', ';');

// Split the string by your separator -> you will get an array filled with fields
string[] contentArr = content.Split(';');
// Access any field you'd like by indexes
var The14thField = contentArr[13];

关于C#从csv中提取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58114741/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com