SA-MP Forums Archive
Splitting an integer - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Splitting an integer (/showthread.php?tid=451472)



Splitting an integer - Daddy Yankee - 17.07.2013

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


Re: Splitting an integer - IstuntmanI - 17.07.2013

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


Re: Splitting an integer - Vince - 17.07.2013

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.


Re: Splitting an integer - Daddy Yankee - 17.07.2013

Thank you both, it helped alot.