# Integer Arrays

Page 1 of 1

## 3 Replies - 577 Views - Last Post: 10 October 2011 - 02:15 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=250517&amp;s=f9e44d1d09a43ce7fd51e1523ebe54a7&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 s3thst4

• a * a = (b * b) + (c * c) - 2(b)(c)cos(A)

Reputation: 10
• Posts: 587
• Joined: 20-November 08

# Integer Arrays

Posted 09 October 2011 - 09:08 AM

Is there any method for ints equivalent to "ToCharArray"?

I need to enter a number (for instance, 5532) and I want to put it into an int array, like each part of the number is a separate element.

The only thing I can think to do is to use a loop to put each number into the array, but I can't think of how to do that.
Is This A Good Question/Topic? 0

## Replies To: Integer Arrays

### #2 CodingSup3rnatur@l-360

Reputation: 999
• Posts: 972
• Joined: 30-September 10

## Re: Integer Arrays

Posted 09 October 2011 - 09:28 AM

Hi,

There is no method in the framework that will do that directly. However, you would do it with a loop (or use LINQ).

You can treat the string as an array of characters, meaning you can loop through it as such, accessing elements using an index. So, you first need to create an int array that has the same length of the string the user entered (use the Length property of the string class to do this). You then need to loop through the entered string (I would use a for loop), trying to parse each character to an integer (for which I would use int.TryParse(). As you parse each character to an int, assign it to the corresponding position in your int array

### #3 s3thst4

• a * a = (b * b) + (c * c) - 2(b)(c)cos(A)

Reputation: 10
• Posts: 587
• Joined: 20-November 08

## Re: Integer Arrays

Posted 09 October 2011 - 09:39 AM

Ahhh! I appreciate it so much! Thank you.

### #4 marinus

Reputation: 135
• Posts: 575
• Joined: 14-April 10

## Re: Integer Arrays

Posted 10 October 2011 - 02:15 AM

An example

```  static void Main(string[] args)
{
int []iArr = StringToIntConverter("55344654",true);
}
public static int[] StringToIntConverter(string strData,bool Reverse)
{
int[] iArray = new int[strData.Length];

if (!Reverse) for (int i = 0; i < strData.Length; i++)
iArray[i] = int.Parse(strData[i].ToString());

else for (int i = 0; i < strData.Length; i++)
iArray[i] = int.Parse(strData[(strData.Length - 1) - i].ToString());

return iArray;
}

```

This post has been edited by Curtis Rutland: 11 October 2011 - 08:53 AM
Reason for edit:: removed size tags from unreadable code