[英]how to split the values of column in datatable of dataset?
In my dataset I have many rows, 在我的数据集中,我有很多行,
In first row last column has the value is "12356.56@Firefox 1@23423"
In Second row same column has the value is "12356.56@Chrome2.0@23423"
In Third row same column has the value is "3423@Firefox 14.0@sdfsd"
here instead of displaying same value like above.. 而不是像上面那样显示相同的值..
I need to display just "Firefox" if that column has Firefox in UI
I need to display just "Chrome" if that column has Chromein UI
how can i do it... 我该怎么做...
Use this helper function 使用此辅助函数
public static string GetBrowser(string str)
{
str = str.ToUpper();
if(str.Contains("CHROME"))
{
return "Chrome";
}
else if(str.Contains("FIREFOX"))
{
return "Firefox";
}
return "Unknown";
}
Then when you bind the dataset to the UI use it to display the value. 然后,当您将数据集绑定到UI时,使用它来显示值。
If you have a list of things you want to check for, you can use .Contains
to check: 如果您有要检查的事项列表,可以使用.Contains
检查:
var myValue = myDS[rowIndex][lastColumn].ToString();
if (myValue.Contains("Firefox"))
return "Firefox";
else if (myValue.Contains("Chrome"))
return "Chrome";
else
return "Unknown";
Demo: http://ideone.com/pMVeD 演示: http : //ideone.com/pMVeD
From the examples you've given, it appears the following logic may work, but it should be tested against a wider variety of sample values: 从您给出的示例中可以看出,以下逻辑可能有效,但应针对更多样本值进行测试:
var myValue = myDS[rowIndex][lastColumn].ToString();
var parts = myValue.Split('@');
var browser = parts[1].Split(' ','0','1','2','3','4','5','6','7','8','9');
return browser[0];
Demo: http://ideone.com/NrY1e 演示: http : //ideone.com/NrY1e
Here is code. 这是代码。 This might help. 这可能有所帮助。
DataSet ds = new DataSet();
//DataTable dt = new DataTable();
ds.Tables.Add("table0");
DataColumn dc = new DataColumn("browser");
ds.Tables[0].Columns.Add(dc);
ds.Tables[0].Rows.Add("12356.56@Firefox1@23423");
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
string str = ds.Tables[0].Rows[i][0].ToString();
if((str.ToLower().CompareTo("firefox"))!=0)
{
ds.Tables[0].Rows[i][0] = "firefox";
}
}
_gridView.DataSource = ds;
_gridView.DataBind();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.