Knowing the type of data. - 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: Knowing the type of data. (
/showthread.php?tid=571079)
Knowing the type of data. -
Ahmad45123 - 15.04.2015
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.
Re: Knowing the type of data. -
R0 - 15.04.2015
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
}
Re: Knowing the type of data. -
Ahmad45123 - 15.04.2015
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.