Checking characters in string -
Riwerry - 29.01.2014
Hello guys, already got code to check if is the first character of string big, also after underscore is big: example
Name_
Lastname .. Check code for that.
Code:
pawn Код:
new pos = strfind(inputtext, "_", true);
if(pos != -1)
{
if(inputtext[pos + 1] >= 'A' && inputtext[pos + 1] <= 'Z')
{
//my code here
}
}
But I want to check if all other characters are small example N
ame_L
astname
Re: Checking characters in string -
Wizz123 - 29.01.2014
pawn Код:
public NameFix(const name[])
{
for(new i=0, j=strlen(name); i<j; i++)
{
name[i] = toupper(name[i]);
}
return name;
}
There we go.
Re: Checking characters in string -
Riwerry - 29.01.2014
error 022: must be lvalue (non-constant)
name[i] = toupper(name[i]);
Re: Checking characters in string -
Wizz123 - 29.01.2014
Sorry my fault.
pawn Код:
public NameFix(name[])
{
for(new i=0, j=strlen(name); i<j; i++)
{
name[i] = toupper(name[i]);
}
return name;
}
Re: Checking characters in string -
Riwerry - 29.01.2014
I am having undefined symbol name here:
if (NameCheck (inputtext) && NameFix(name[]))
Re: Checking characters in string -
Wizz123 - 29.01.2014
Use
pawn Код:
new name [MAX_PLAYER_NAME+1];
on the top of your script
Re: Checking characters in string -
Riwerry - 29.01.2014
I needed to edit every name variable becouse I got errors warnig so it shadows with includes, i tried this everything replaced with this and I got this now

C:\Users\Jakub\Desktop\Server\gamemodes\LVRP.pwn(5 37) : error 029: invalid expression, assumed zero
C:\Users\Jakub\Desktop\Server\gamemodes\LVRP.pwn(6 79) : warning 219: local variable "nametocheck" shadows a variable at a preceding level
line if (NameCheck (inputtext) && NameFix(nametocheck[]))
Re: Checking characters in string -
Konstantinos - 29.01.2014
After checking that the name is valid (Name_Lastname, it uses only 1 underscore and not at the start or end etc), use:
pawn Код:
if (CheckChars(inputtext))
{
// your code
}
pawn Код:
stock CheckChars(const source[], length = sizeof (source))
{
if (!(--length)) return 0;
new
pos = strfind(source, "_");
for (new i; i != length; ++i)
{
if (!i || i == pos + 1)
{
switch (source[i])
{
case 'A' .. 'Z': continue;
default: return 0;
}
}
else if (i && i != pos && i != pos + 1)
{
switch (source[i])
{
case 'a' .. 'z': continue;
default: return 0;
}
}
}
return 1;
}
Re: Checking characters in string -
Riwerry - 29.01.2014
Wow Konstantinos, you are saving me again

yesterday you typed working code too.. Is possible to put this character check function to stock, which you sent me yesterday? Thanx mate
pawn Код:
NameCheck (const sz_Name[])
{
new
lenght = strlen(sz_Name);
if (!lenght) return 0;
new
us_count,
sp_count,
pos = strfind(sz_Name, "_", true);
for (new i; i != lenght; ++i)
{
if (sz_Name[i] == '_') ++us_count;
if (sz_Name[i] == ' ') ++sp_count;
}
return (lenght <= 19 && sz_Name[0] >= 'A' && sz_Name [0] <= 'Z' && sz_Name [pos+1] >= 'A' && sz_Name [pos+1] <= 'Z' && us_count == 1 && sp_count == 0);
}
Re: Checking characters in string -
Konstantinos - 29.01.2014
EDIT: Code on the next post.