I want the number of the string put into two ints? Any ideas?
For example the string (9, 11) would be int x = 9 and int y = 11
Printable View
I want the number of the string put into two ints? Any ideas?
For example the string (9, 11) would be int x = 9 and int y = 11
You can use IndexOf and SubString to copy part of stringQuote:
Originally posted by jordan23
I want the number of the string put into two ints? Any ideas?
For example the string (9, 11) would be int x = 9 and int y = 11
Code:string myString = "(9, 11)";
int x;
int y;
//Get the position of ","
int pos = myString.IndexOf(",");
//Get the position of ")"
int pos2 = myString.IndexOf(")");
//First part
x = Convert.ToInt32(myString.Substring(1,pos-1).Trim());
//2nd part
y = Convert.ToInt32(myString.Substring(pos+1, pos2-1-pos).Trim());
MessageBox.Show(x.ToString() + " " + y.ToString());
Thanks. That was exactly what I needed.