【发布时间】:2014-10-05 07:51:22
【问题描述】:
我想知道你是否云帮助我?
我有一个由商品、价格和数量组成的数组。 如果项目存在,则必须更新价格和数量的数组,如果不存在则必须添加
这是我尝试过的代码:
if (line.Contains(ItemCode))
{
string[] details = line.Split(new string[] { "|" }, StringSplitOptions.None);
{
for (int i = 0; i < details.Length; i++)
{
if (details[i].Contains(ItemCode))
{
string[] line_details = details[i].Split(',');
string replace = line_details[2].Trim() + "," + line_details[3].Trim();
double NewQty = double.Parse(Qty) + double.Parse(line_details[2]);
double NewPrice = (double.Parse(UnitPrice) * double.Parse(Qty));
double NewUnitPrice = NewPrice + double.Parse(line_details[3]);
string new_replace = NewQty + "," + NewUnitPrice;
line = line.Replace(replace, new_replace);
}
}
}
}
else
{
line = line + "\"Detail\",0," + Qty + "," + (double.Parse(UnitPrice) * double.Parse(Qty)) + "," + InclusivePrice + ",\"" + UnitUsed + "\"," + TaxType + "," + DiscountType + "," + DiscountPercentage + ",\"" + ItemCode + "\",\"" + Description + "\"," + SearchType + "," + "\"\"" + ",\"" + MultiStore + "\"|" + Environment.NewLine;
}
它不工作你能帮我解决这个问题吗?
【问题讨论】:
-
用
string[] details = line.Split...;代替List<string> details = new List<string>(line.Split(new string[] { "|" }, StringSplitOptions.None));