Splitting an integer
#1

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
Reply
#2

Код:
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.
Reply
#3

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 of the number, not the number itself.
pawn Код:
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.
Reply
#4

Thank you both, it helped alot.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)