Results 1 to 3 of 3

Thread: Convert Part of string to int [resolved]

  1. #1

    Thread Starter
    Addicted Member jordan23's Avatar
    Join Date
    Dec 2002
    Posts
    166

    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.

  2. #2
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877

    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 :

  3. #3

    Thread Starter
    Addicted Member jordan23's Avatar
    Join Date
    Dec 2002
    Posts
    166
    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
  •  



Click Here to Expand Forum to Full Width