如何从c#的新行取子字符串
本文关键字:新行取 字符串 | 更新日期: 2023-09-27 18:11:01
我有一个文件,格式如下
abc,def,ghi,365.23475,bk,2324,1,
nhk,73.9083,knd,lees,73.584,df,100,
我需要取第二行第四个' '之后的值。
string input = "abc,def,ghi,365.23475,bk,2324,1,'nnhk,73.9083,knd,lees,73.584,df,100,";
string result = input.Split(''n')[1].Split(',')[4]; //73.9083
试试这个
var lines = File.ReadAllLine(PATH_TO_THE_FILE);
string result;
if (lines.Count > 0) {
var temp = lines[1].Split(',');
if (temp.Length > 3) {
result = temp[3];
} else {
result = null;
}
} else {
result = null;
}