strval
#1

Hello,

what is return in strval() when:

new value = strval("test");

?

Thanks
Reply
#2

https://sampwiki.blast.hk/wiki/Strval

in your case, will be 0.
Reply
#3

pawn Код:
#include <a_samp>

main() { printf("value: %i", strval("test")); }
Oh..lazy people.
Reply
#4

Oh no... Is there any function like IsString ?
Reply
#5

You can make one, try this for example:
pawn Код:
IsNumeric(const string[])
{
    for (new i = 0, j = strlen(string); i < j; i++)
    {
        if (string[i] > '9' || string[i] < '0') return 0;
    }
    return 1;
}
Use this to check if a string is numeric.
Reply
#6

Thanks
Reply
#7

I recommend using the version from y_utils as it's about 3 times as fast (Benchmarked with 10000 loops, your version took 9ms while this one only 3ms - the difference is pretty unnoticable, but still):

pawn Код:
stock isnumeric(str[])
{
    new
        ch,
        i;
    while ((ch = str[i++])) if (!('0' <= ch <= '9')) return 0;
    return 1;
}
Reply
#8

Quote:
Originally Posted by LarzI
Посмотреть сообщение
I recommend using the version from y_utils as it's about 3 times as fast (Benchmarked with 10000 loops, your version took 9ms while this one only 3ms - the difference is pretty unnoticable, but still):

pawn Код:
stock isnumeric(str[])
{
    new
        ch,
        i;
    while ((ch = str[i++])) if (!('0' <= ch <= '9')) return 0;
    return 1;
}
or just use y_faster_everything_because_we_are_obsessed_with_s peed_plugin
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)