strmfind numbers.
#1

How can I check if a string contains numbers?
Without repeating
if(strfind(playername(playerid), "0", true) != -1)

Ten times.
Reply
#2

You check each character with a loop:
pawn Code:
ContainsNumbers(const _str_[])
{
    for (new i, j = strlen(_str_); i != j; i++)
    {
        if ('0' <= _str_[i] <= '9') return 1;
    }
    return 0;
}
Reply
#3

Is there any other smaller way to check other than stocks?
Reply
#4

Use this function (with loop, i.e. with repeating, because without repeating isn't work):
Code:
stock
	NumbersInString(const string[], string_length = sizeof string)
{
	static pos;
	for(pos = -1; ++pos != string_length;)
	{
		switch (string[i])
		{
			case '\0':
				break;
			case '0' .. '9':
				return 1;
		}
	}
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)