only letters
#1

Hello guys I need to check if in the string is only letters, so I created a stock for this, but it doesn't work.
Here is it:
PHP код:
stock OnlyLetters(text[])
{
    for(new 
'a'<= 'z'i++)
    {
        for(new 
i2 'A'i2 <= 'Z'i2++)
        {
            new 
string[256], string2[256];
            
format(stringsizeof(string), "%c"i);
            
format(string2sizeof(string2), "%c"i2);
            if(
strfind(textstringtrue) == && strfind(textstring2true) == 1)
            {
                return 
0;
            }
        }
    }
    return 
1;

Please help
Reply
#2

You need to loop from position 0 until string's length-1.
Check each character if it is in range of 'a' to 'z' OR 'A' to 'Z' using array index (in example text[i]).
But it is better to do it the other way around. If a character is not a letter, return 0 right away to avoid needless loop iterations.
Reply
#3

Quote:
Originally Posted by ******
Посмотреть сообщение
Код:
// At the top of your code.
#include <Pawn.Regex>
new Regex:g_reNameCheck;

// In OnGameModeInit (use `*` not `+` if empty strings are valid).
g_reNameCheck = Regex_New("^[a-zA-Z]+$");

// Your function (not stock, why did you make it stock?)
bool:OnlyLetters(const text[])
{
    return Regex_Check(text, g_reNameCheck);
}
I don't want to check the player's name. I want to check in my gang system if there are only letters. I don't want gangs with names like: Gr0ve Street Fam1l1es or "12541265zdwas" gang
Reply
#4

Quote:
Originally Posted by Kraeror
Посмотреть сообщение
I don't want to check the player's name. I want to check in my gang system if there are only letters. I don't want gangs with names like: Gr0ve Street Fam1l1es or "12541265zdwas" gang
****** gave you the code that uses Pawn RegEx plugin and told you the method to check it. There's nothing related to "player's name" - it can be used for any text (string).
Reply
#5

Quote:
Originally Posted by ******
Посмотреть сообщение
Код:
// At the top of your code.
#include <Pawn.Regex>
new Regex:g_reNameCheck;

// In OnGameModeInit (use `*` not `+` if empty strings are valid).
g_reNameCheck = Regex_New("^[a-zA-Z]+$");

// Your function (not stock, why did you make it stock?)
bool:OnlyLetters(const text[])
{
    return Regex_Check(text, g_reNameCheck);
}
I did it, but it didn't accept the spaces. I mean "Grove Street" is not accepted. It has to be "GroveStreet". How can I allow the spaces?
Reply
#6

I think I did it, I just pasted a space inside the brackets:
Quote:

^[a-zA-Z ]+$

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)