|
-
Jul 23rd, 2004, 03:08 PM
#1
Thread Starter
Addicted Member
Convert Part of string to int [resolved]
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
Last edited by jordan23; Jul 24th, 2004 at 08:20 AM.
-
Jul 24th, 2004, 05:46 AM
#2
Re: Convert Part of string to int
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
You can use IndexOf and SubString to copy part of string
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());
[VBF RSS Feed]
There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.
If I have been helpful, Please Rate my Post. Thanks.
This post was powered by : 
-
Jul 24th, 2004, 08:19 AM
#3
Thread Starter
Addicted Member
Thanks. That was exactly what I needed.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|