PDA

View Full Version : Splitting an integer


Daddy Yankee
17/07/2013, 11:25 AM
Alright so I have an integer for example 123456, can I get each number into a different value like number1, number2 and so on without having a delimiter ? Thanks in advance

IstuntmanI
17/07/2013, 11:29 AM
new lsString[ 16 ], liNumbers[ 16 ], liNumber = 123456, liLength;
format( lsString, 16, "%d", liNumber );
liLength = strlen( lsString );
for( new i = 0; i < liLength; i ++ )
{
liNumbers[ i ] = lsString[ i ];
}

This is the best method I can think now.

Vince
17/07/2013, 11:43 AM
I'm a little confused myself right now, but I don't think that loop is going to work at all. When you format the number into a string, the string itself will hold the ASCII representation (http://www.asciitable.com/) of the number, not the number itself.

new string[] = "123456";
new string[] = {'1', '2', '3', '4', '5', '6'};
new string[] = {49, 50, 51, 52, 53, 54};

Those would all have the same meaning. So you'd need to subtract 48 to get the actual number.

Daddy Yankee
17/07/2013, 11:49 AM
Thank you both, it helped alot.