Variable length
#1

How can I know the length of an int variable?
Ex.: PlayerInfo[playerid][pLevel]

I've tried with: new levelength = strlen(PlayerInfo[playerid][pLevel]);
Also: new levelength = sizeof(PlayerInfo[playerid][pLevel]);

But it doesn't work.

Thanks
Reply
#2

The length? Don't you mean the value?
If you mean length, use strlen. (string length)

pawn Код:
new
    tmpString[ 64 ];
   
    format( tmpString, sizeof( tmpString ), "%d", PlayerInfo[playerid][pLevel] );
    format( tmpString2, sizeof( tmpString2 ), "%d", strlen(tmpString) );
    print( tmpString2 );
Reply
#3

I need to count the characters in PlayerInfo[playerid][pLevel].

In example:
PlayerInfo[playerid][pLevel] = 128

I need a way to know that this variable have 3 digits (1,2, -> [Length] = 3;

It's possible?

Sorry for my english.
Reply
#4

Yep, that's what the "snippet" I posted does.
Reply
#5

Use valstr and then strlen

https://sampwiki.blast.hk/wiki/Scripting...ons_Old#valstr
https://sampwiki.blast.hk/wiki/Scripting...ons_Old#strlen
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)