Check if string is a number - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Check if string is a number (
/showthread.php?tid=208551)
Check if string is a number -
GiS - 08.01.2011
Hey,
how can I check if the insert data in a string is a number or not?
Re: Check if string is a number -
Alex_Valde - 08.01.2011
Use IsNumeric function:
pawn Code:
IsNumeric(const string[])
{
for (new i = 0, j = strlen(string); i < j; i++)
{
if (string[i] > '9' || string[i] < '0') return 0;
}
return 1;
}
Re: Check if string is a number -
GiS - 08.01.2011
pawn Code:
new input;
format(input, sizeof(input), "%i", inputtext);
if(input < 12 || input > 120)
{
What's wrong on that format?
It says:
PHP Code:
(407) : error 035: argument type mismatch (argument 1)
(407) : error 035: argument type mismatch (argument 1)
Pawn compiler 3.2.3664 Copyright (c) 1997-2006, ITB CompuPhase
2 Errors.
Re: Check if string is a number -
Alex_Valde - 08.01.2011
Try this:
pawn Code:
if(inputtext < 12 || inputtext > 120)
But you need to change something else too.
This is full code:
pawn Code:
new input[128];//You need to define the length of the input before formating it.
format(input, sizeof(input), "%i", inputtext);
if(inputtext < 12 || inputtext > 120)
{
Re: Check if string is a number -
GiS - 08.01.2011
Well I do this in the OnDialogResponse Callback.
I get the following error:
pawn Code:
(406) : error 033: array must be indexed (variable "inputtext")
pawn Code:
if(inputtext < 12 || inputtext > 120)
{
//...
Re: Check if string is a number -
Alex_Valde - 08.01.2011
Ahh, sorry didn't know that...
Then try:
pawn Code:
if(strval(inputtext) < 12 || strval(inputtext) > 120)