Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I need to convert a String to Integer.

 

The String consists of:

3 23 5 7 4 8 10 12

 

I would like to store each Number in the String into an array of Integers. Each Integer is seperate by a space. Any idea how can I do that?

 

Thanks in advance.

  • Administrators
Posted

       private int[] StringToIntegerArray(string numbers)
       {
           string[] nums = numbers.Split(' ');

           int[] ints = new int[nums.Length];

           for (int i=0;i                ints[i] = int.Parse(nums[i]);

           return ints;
       }

should get you started - you will need to provide some error checking to validate the initial string etc though.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

Other ways are:

 

Using the Convert class en typecasting (using (int)StringS )

For questions about VS .net extensibility, please fire at me! :)

For readability, please use the [ CS][/CS ] tags

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...