There probably is easier ways, but here is something I whipped up for you.
Code:private void button1_Click(object sender, System.EventArgs e) { string[] x; string[] y; int counter; int interiorCounter; counter = 0; interiorCounter = 0; // X is our original array. x = new string[5]; x[0] = "hello"; x[1] = "@"; x[2] = "something"; x[3] = "@"; x[4] = "@"; // We need to find out how many elements we are going to be adding. for (int i = 0; i <= x.GetUpperBound(0); i++) { if (x[i] == "@") counter++; } // Now we know how many to add, we need to add the x // array amount to the counter variable for the total. counter += x.GetUpperBound(0) + 1; // Now instantiate our new array. y = new string[counter]; // Start filling the new array. for (int i = 0; i <= x.GetUpperBound(0); i++) { if(x[i] == "@") { y[interiorCounter] = "@"; interiorCounter++; y[interiorCounter] = "your newly added element"; } else { y[interiorCounter] = x[i]; } interiorCounter++; } // Show your newly added stuff.... for(int i = 0; i <= y.GetUpperBound(0); i++) { MessageBox.Show(y[i].ToString()); } }




Reply With Quote