我有以txt格式存储的数据,然后显示数据。我想在图片中得到总共QOH,我总体上有问题。
diff <- 1 - rowSums(df)
谢谢!
答案 0 :(得分:3)
为您的QOH添加计数器,如下所示:
public void DisTranswe()
{
Console.Clear();
FileStream fs = new FileStream("TransactionHistory\\weekend\\transcationhistory.txt", FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader(fs);
int sum=0;
while ((str = sr.ReadLine()) != null)
{
string[] data = str.Split('#');
string id = data[0];
string date = data[1];
string qty = data[2];
string payment = data[3];
string note = data[4];
sum=sum+int.Parse(qty);
//output
Console.WriteLine("IdTransaksi");
Console.WriteLine(id);
Console.WriteLine("DateTransaksi");
Console.WriteLine(date);
Console.WriteLine("QOH");
Console.WriteLine(qty);
Console.WriteLine("TotalPayment");
Console.WriteLine(payment);
Console.WriteLine("Note");
Console.WriteLine(note);
}
Console.WriteLine("SUM");
Console.WriteLine(sum);
sr.Close();
fs.Close();
}
答案 1 :(得分:-2)
试试这个:
int qoh =
File
.ReadAllLines("TransactionHistory\\weekend\\transcationhistory.txt")
.Sum(x => int.Parse(x.Split('#')[2]));