0
解析要檢查是否有在CSV文件中的列字段中的任何空值,也後/數量列,如果是空的整行不應該寫不應該有空值輸出文件。CSV文件中的C#
name,number,gender,country
iva 1/001 f Antartica
aaju 2/002 m russia
lax 3/ m brazil
ana 4/004 f Thailand
vis 5/005 m
例如,第3和第5行不應寫入輸出文件。
using (StreamWriter file = new StreamWriter(filepathop)) {
for (int i = 0; i < csv.Length; i++) {
{
if (i == 0) {
file.WriteLine(header + "," + "num" + "," + "serial" + "," + "date");
}
else {
var newline = new StringBuilder();
string[] words = csv[i].Split(',');
string[] no = words[1].Split('/');
string number = no[0];
string serial = no[1];
newline.Append(number + "," + serial + "," + tokens[0]);
file.WriteLine(csv[i] + "," + newline);
}
}
}
}
}
}
}
您輸入不會出現用逗號分割,這似乎是固定的列寬,空格分開嗎? – yacc
實際上它是一個CSV文件。 – Dithan