only letters - 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: only letters (
/showthread.php?tid=661523)
only letters -
Kraeror - 07.12.2018
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 i = 'a'; i <= 'z'; i++)
{
for(new i2 = 'A'; i2 <= 'Z'; i2++)
{
new string[256], string2[256];
format(string, sizeof(string), "%c", i);
format(string2, sizeof(string2), "%c", i2);
if(strfind(text, string, true) == 1 && strfind(text, string2, true) == 1)
{
return 0;
}
}
}
return 1;
}
Please help
Re: only letters -
Calisthenics - 07.12.2018
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.
Re: only letters -
Kraeror - 07.12.2018
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
Re: only letters -
Logic_ - 07.12.2018
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).
Re: only letters -
Kraeror - 08.12.2018
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?
Re: only letters -
Kraeror - 08.12.2018
I think I did it, I just pasted a space inside the brackets: