我们如何从数组中过滤文本。 [英] How can we filter text from array.

查看:71
本文介绍了我们如何从数组中过滤文本。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个返回数据的数组,如3,6,9,12,15 ..(3的乘法)

 DataTable dt =  new  DataTable(); 
string GridData = ViewState [ ShowItem ]的ToString();
string [] FilterData = GridData.Split(' ^');

数组返回数据,如..

FilterData [ 0 ] = Pizza; (项目)
FilterData [ 1 ] = 2个$; (价格)
FilterData [ 2 ] = 2\" ; (数量)
FilterData [ 3 ] = 汉堡;
FilterData [ 4 ] = 5 $ ;
FilterData [ 5 ] = 1 ;
FilterData [ 6 ] = Cesa ;
FilterData [ 7 ] = 7 $ ;
FilterData [ 8 ] = 3 ;





现在我想在数据库中按列顺序输入上述数据,如:

 项目价格数量总计(价格*数量) 



现在我想运行一个添加数据的循环特殊字段如:

  for  int  nIndex =  0 ; nIndex <  FilterData.Length; nIndex ++)
{
DataRow drow = dt.NewRow();
drow [ ProductItem] = FilterData [nIndex] .ToString(); (添加所有项目)
drow [ Cost] = FilterData [nIndex] .ToString (); (添加所有费用)
drow [ 数量] = FilterData [nIndex] .ToString (); (添加所有数量)
double 总计= Convert.ToDouble(FilterData [nIndex] .ToString())* Convert.ToInt32(FilterData [nIndex] .ToString ()); (添加所有费用*数量)
drow [ 总计] =总计;
dt.Rows.Add(卓尔);
}



所以任何人都可以帮助我如何运行循环,以便将数据添加到特定列,如:



项目价格数量总计(价格*数量)

比萨饼2 2 4
汉堡5 1 5
Cesa 7 3 21

解决方案

;(Price)
FilterData [ 2 ] = 2;(数量)
FilterData [ 3 ] = Burger;
FilterData [ 4 ] = 5


;
FilterData [ 5 ] = 1;
FilterData [ 6 ] = Cesa;
FilterData [ 7 ] = 7

;
FilterData [ 8 ] = 3 ;





现在我想在数据库中按列顺序输入上述数据,如:

 项目价格数量总计(价格*数量) 



现在我想运行一个添加数据的循环特殊字段如:

  for  int  nIndex =  0 ; nIndex <  FilterData.Length; nIndex ++)
{
DataRow drow = dt.NewRow();
drow [ ProductItem] = FilterData [nIndex] .ToString(); (添加所有项目)
drow [ Cost] = FilterData [nIndex] .ToString (); (添加所有费用)
drow [ 数量] = FilterData [nIndex] .ToString (); (添加所有数量)
double 总计= Convert.ToDouble(FilterData [nIndex] .ToString())* Convert.ToInt32(FilterData [nIndex] .ToString ()); (添加所有费用*数量)
drow [ 总计] =总计;
dt.Rows.Add(卓尔);
}



所以任何人都可以帮助我如何运行循环,以便将数据添加到特定列,如:



项目价格数量总计(价格*数量)

比萨饼2 2 4
汉堡5 1 5
Cesa 7 3 21


I have an array which return data in size like 3,6,9,12,15.. (multiplication of 3)

DataTable dt = new DataTable();
string GridData = ViewState["ShowItem"].ToString();
string[] FilterData = GridData.Split('^');

Above array return data like..

FilterData [0] = "Pizza";     (Item)
FilterData [1] = "2$";        (Price)
FilterData [2] = "2";         (Quantity)
FilterData [3] = "Burger";
FilterData [4] = "5$";
FilterData [5] = "1";
FilterData [6] = "Cesa";
FilterData [7] = "7$";
FilterData [8] = "3";



now I want to enter above data as column wise in database like:

Item      Price    Quantity    Total(Price*Quantity)


now I want to run a loop that add data of particular field like:

for (int nIndex = 0; nIndex < FilterData.Length; nIndex++)
 {
 DataRow drow = dt.NewRow();
drow["ProductItem"] = FilterData[nIndex].ToString();   (Add all Item)
drow["Cost"] = FilterData[nIndex].ToString();          (Add all Cost)
drow["Quantity"] = FilterData[nIndex].ToString();       (Add all Quantity)
double Total= Convert.ToDouble(FilterData[nIndex].ToString()) * Convert.ToInt32(FilterData[nIndex].ToString());       (Add all cost*Quantity)
                    drow["Total"] = Total;
dt.Rows.Add(drow);
}


So can anybody help me how could I run the loop so it add data to particular column like:

Item   Price   Quantity  Total(Price*Quantity)

Pizza    2       2             4
Burger   5       1             5
Cesa     7       3             21

解决方案

"; (Price) FilterData [2] = "2"; (Quantity) FilterData [3] = "Burger"; FilterData [4] = "5


"; FilterData [5] = "1"; FilterData [6] = "Cesa"; FilterData [7] = "7


"; FilterData [8] = "3";



now I want to enter above data as column wise in database like:

Item      Price    Quantity    Total(Price*Quantity)


now I want to run a loop that add data of particular field like:

for (int nIndex = 0; nIndex < FilterData.Length; nIndex++)
 {
 DataRow drow = dt.NewRow();
drow["ProductItem"] = FilterData[nIndex].ToString();   (Add all Item)
drow["Cost"] = FilterData[nIndex].ToString();          (Add all Cost)
drow["Quantity"] = FilterData[nIndex].ToString();       (Add all Quantity)
double Total= Convert.ToDouble(FilterData[nIndex].ToString()) * Convert.ToInt32(FilterData[nIndex].ToString());       (Add all cost*Quantity)
                    drow["Total"] = Total;
dt.Rows.Add(drow);
}


So can anybody help me how could I run the loop so it add data to particular column like:

Item   Price   Quantity  Total(Price*Quantity)

Pizza    2       2             4
Burger   5       1             5
Cesa     7       3             21


这篇关于我们如何从数组中过滤文本。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆