containsLetters(string[]) - 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: containsLetters(string[]) (
/showthread.php?tid=250864)
containsLetters(string[]) -
borba - 24.04.2011
Sup guys!
I'm trying to make a function that checks if there's Letters in a string, cause in my Dialog, I only accept number 0~9.
pawn Код:
stock onlyNumbers(string[])
{
new bool:contains = false;
for(new c = 0; c < sizeof(string); c++)
{
new character = strval(string(c));
if(character >= '0' && character <= '9')
{
// do nothing
}
else
{
contains = true;
return false;
break;
}
}
if(!contains) return true;
}
But I'm getting these errors:
Код:
C:\Users\Gustavo\Desktop\samp03csvr_R2-2_win32\gamemodes\fcrp.pwn(1551) : warning 224: indeterminate array size in "sizeof" expression (symbol "")
C:\Users\Gustavo\Desktop\samp03csvr_R2-2_win32\gamemodes\fcrp.pwn(1553) : error 012: invalid function call, not a valid address
C:\Users\Gustavo\Desktop\samp03csvr_R2-2_win32\gamemodes\fcrp.pwn(1553) : warning 215: expression has no effect
C:\Users\Gustavo\Desktop\samp03csvr_R2-2_win32\gamemodes\fcrp.pwn(1553) : error 001: expected token: ";", but found ")"
C:\Users\Gustavo\Desktop\samp03csvr_R2-2_win32\gamemodes\fcrp.pwn(1553) : error 029: invalid expression, assumed zero
C:\Users\Gustavo\Desktop\samp03csvr_R2-2_win32\gamemodes\fcrp.pwn(1553) : fatal error 107: too many error messages on one line
Re: containsLetters(string[]) -
Jefff - 24.04.2011
pawn Код:
stock onlyNumbers(string[],len=0)
{
len = strlen(string);
for(new c = 0; c < len; c++)
{
if(!('0' <= string[c] <= '9')) return false;
}
return true;
}
Re: containsLetters(string[]) -
Vince - 24.04.2011
pawn Код:
stock IsNumeric(const str[])
{
new len = strlen(str);
if(!len) return false;
for(new i; i < len; i++)
{
if(!('0' <= str[i] <= '9')) return false;
}
return true;
}
Too late. Again.
Re: containsLetters(string[]) -
borba - 24.04.2011
Thanks guys, you're a genius.
Re: containsLetters(string[]) -
playbox12 - 24.04.2011
You could simply use the stock IsNumeric, to determine if the string is completely numeric, if it returns false, there are characters or letters in it.
Usage;
if(!IsNumeric(string))
pawn Код:
stock IsNumeric(str[])
{
new ch, i;
while ((ch = str[i++])) if (ch < '0' || ch > '9') return 0;
return 1;
}
EDIT: Beaten twice in a row, both of you good job. I seriously need to refresh before posting.