Editing a pre-written function/stock
#1

Hey, guys. I've been using a pre-written function for checking RP Names, problem is it seems to work fine up until you use an RP name such as

Firstname_

And it still lets it pass as it has an underscore. I've tried multiple ways to try count the characters AFTER the _ but I can't seem to figure it out without causing it to completely work in a different way. The function i'm using is this

pawn Код:
stock NameValidator(name[])
{
    new underline=0;


    if(strfind(name,"[",true) != (-1)) return 0;
    else if(strfind(name,"]",true) != (-1)) return 0;
    else if(strfind(name,"$",true) != (-1)) return 0;
    else if(strfind(name,"(",true) != (-1)) return 0;
    else if(strfind(name,")",true) != (-1)) return 0;
    else if(strfind(name,"=",true) != (-1)) return 0;
    else if(strfind(name,"@",true) != (-1)) return 0;
    else if(strfind(name,"1",true) != (-1)) return 0;
    else if(strfind(name,"2",true) != (-1)) return 0;
    else if(strfind(name,"3",true) != (-1)) return 0;
    else if(strfind(name,"4",true) != (-1)) return 0;
    else if(strfind(name,"5",true) != (-1)) return 0;
    else if(strfind(name,"6",true) != (-1)) return 0;
    else if(strfind(name,"7",true) != (-1)) return 0;
    else if(strfind(name,"8",true) != (-1)) return 0;
    else if(strfind(name,"9",true) != (-1)) return 0;
    new maxname = strlen(name);
    for(new i=0; i<maxname; i++)
    {
       if(name[i] == '_') underline ++;
    }
    if(underline != 1) return 0;
    name[0] = toupper(name[0]);
    for(new x=1; x<maxname; x++)
    {
        if(name[x] == '_') name[x+1] = toupper(name[x+1]);
        else if(name[x] != '_' && name[x-1] != '_') name[x] = tolower(name[x]);
    }


    return 1;
}
I've tried counting the string but I have no idea how to go about checking for the underscore... other than trying

pawn Код:
if(underline == 1)
{
    //do something here which I just can't seem to crack
}
Any ideas how to check for an underscore? Then make sure after it there is a minimum of 3 characters?
Reply
#2

Why not use:
pawn Код:
if(strfind(name, "_", true) != -1) return 0;
Reply
#3

you could store the "strfound" position of the "_", and subtract it from strlen(name).
if the result>2 (or 3? didnt consider the string end \0, oops) then he last name is long enough?
Reply
#4

Quote:
Originally Posted by zDivine
Посмотреть сообщение
Why not use:
pawn Код:
if(strfind(name, "_", true) != -1) return 0;
Surely that is only checking to see if there is an underscore?

I've tried using strfind but I have no idea how to use the strlen function for checking AFTER the underscore.
Reply
#5

Couldn't work this one out either.
Reply
#6

Edit: I found the solution a while ago, I just forgot to re-post, but I managed to fix this working off of this suggestion
Quote:
Originally Posted by Babul
Посмотреть сообщение
you could store the "strfound" position of the "_", and subtract it from strlen(name).
if the result>2 (or 3? didnt consider the string end \0, oops) then he last name is long enough?
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)