Checking characters in string
#1

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 Name_Lastname
Reply
#2

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.
Reply
#3

error 022: must be lvalue (non-constant)

name[i] = toupper(name[i]);
Reply
#4

Sorry my fault.
pawn Код:
public NameFix(name[])
{
    for(new i=0, j=strlen(name); i<j; i++)
    {
        name[i] = toupper(name[i]);
    }
    return name;
}
Reply
#5

I am having undefined symbol name here:

if (NameCheck (inputtext) && NameFix(name[]))
Reply
#6

Use
pawn Код:
new name [MAX_PLAYER_NAME+1];
on the top of your script
Reply
#7

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[]))
Reply
#8

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;
}
Reply
#9

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);
}
Reply
#10

EDIT: Code on the next post.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)