I
idog
If I start off with a string which contains comma separated ints. I
want to move this into an int array so i can do sorting.
I thought I might get this to work:
int[] test = {textBox1.Text};
What would be the best way to accomplish this?
This is what i came up with:
private void button1_Click(object sender, System.EventArgs e)
{
int [] test;
test = commaStringToArray(textBox1.Text);
// ok here i will do stuff to test[], like sorting
//
textBox2.Text = arrayToCommaString(test);
}
private int[] commaStringToArray(string strComma)
{
string [] strArray;
strArray = strComma.Split(new char[] {','});
int [] intArray = new int [strArray.Length];
for (int i = 0; i < strArray.Length; i++)
intArray = int.Parse(strArray);
return intArray;
}
private string arrayToCommaString(int[] intArray)
{
string strOut = "";
foreach (int i in intArray)
strOut += ", " + i.ToString();
return strOut.Remove(0,2);
}
want to move this into an int array so i can do sorting.
I thought I might get this to work:
int[] test = {textBox1.Text};
What would be the best way to accomplish this?
This is what i came up with:
private void button1_Click(object sender, System.EventArgs e)
{
int [] test;
test = commaStringToArray(textBox1.Text);
// ok here i will do stuff to test[], like sorting
//
textBox2.Text = arrayToCommaString(test);
}
private int[] commaStringToArray(string strComma)
{
string [] strArray;
strArray = strComma.Split(new char[] {','});
int [] intArray = new int [strArray.Length];
for (int i = 0; i < strArray.Length; i++)
intArray = int.Parse(strArray);
return intArray;
}
private string arrayToCommaString(int[] intArray)
{
string strOut = "";
foreach (int i in intArray)
strOut += ", " + i.ToString();
return strOut.Remove(0,2);
}