Hello guys I need your help in split and asign values to two variables, from the following collection:
string[] selectedItems= new string[2] {"26-1", "30-2"};
RESULT: This values will be passed to an method which need A and B as parameters. Please any help will be appreciate it.
First set second set
int A= 26 int A = 30
int B = 2 int B = 2
Loading
Kirtan PatelPosted Dec 11, 2009, 9:59 AM
int a1, b1, a2, b2;
string[] SelectedItem = new string[2] { "26-1", "30-2" };
string[] x = SelectedItem[0].Split('-');
a1 = Convert.ToInt32(x[0]);
b1 = Convert.ToInt32(x[1]);
string[] y = SelectedItem[1].Split('-');
a2 = Convert.ToInt32(y[0]);
b2 = Convert.ToInt32(y[1]);
//Done Assigment to Variables
Raul JuarezPosted Dec 11, 2009, 9:44 AM
strAB[i] = selectedItems[i].Substring(","); Error
I believe strAB[i] should be like this strAB[2,i] .......ok because I always expect pair values example: {4,23}, {2,18},{4,6} etc
selectedItems[i].Substring(","); //ERROR IN HERE
The best overloaded method match for 'string.Substring(int)' has some invalid arguments
METHOD:
protected void lnkDeleteSelected_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(Request.Form["chkSelectedItems"]))
{
string[] selectedItems = Request.Form["chkSelectedItems"].Split(',');
string[,] strAB = new string[2, selectedItems.Length];
for (int i = 0; i < selectedItems.Length; i++)
{
strAB[i] = selectedItems[i].Substring(",");
}
}
naura paxPosted Dec 11, 2009, 2:20 AM