Knowing the type of data.
#1

In a y_ini callback, Is there a way I can detect the type of data in a string.

Like for example:
"32654" would return 1 (which means lets say integer)
and "sdjfguf1540fdfd\sf" would return 2(which is string)

If someone has a function for that, It'd be very appreciated.
Reply
#2

pawn Код:
stock GetVarType(variable[])
{
    new length = strlen(variable), dots, letters, bool:negative = false;
    if(variable[0] == '-') negative = true;
    for(new i; i<length; i++)
    {
        if(negative == false) {
            if((variable[i] == '.') && (i>0) && i<(length-1)) dots++;
        else if((variable[i] > '9') || (variable[i] < '0')) letters++;
        }
        else {
            if((variable[i] == '.') && (i>1) && i<(length-1)) dots++;
            else if(((variable[i] > '9') || (variable[i] < '0')) && (i != 0)) letters++;
        }
    }
    if(dots == 1 && letters == 0) return 1;  // float
    else if(letters > 0 ) return 2; //string
    return 0; // integer
}
Reply
#3

Quote:
Originally Posted by R0
Посмотреть сообщение
pawn Код:
stock GetVarType(variable[])
{
    new length = strlen(variable), dots, letters, bool:negative = false;
    if(variable[0] == '-') negative = true;
    for(new i; i<length; i++)
    {
        if(negative == false) {
            if((variable[i] == '.') && (i>0) && i<(length-1)) dots++;
        else if((variable[i] > '9') || (variable[i] < '0')) letters++;
        }
        else {
            if((variable[i] == '.') && (i>1) && i<(length-1)) dots++;
            else if(((variable[i] > '9') || (variable[i] < '0')) && (i != 0)) letters++;
        }
    }
    if(dots == 1 && letters == 0) return 1;  // float
    else if(letters > 0 ) return 2; //string
    return 0; // integer
}
Thanks alot mate.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)