STRFIND not working?
#1

Hi, This code is supposed to search the name for "[GC]" even when I have it in my name, It still says that it's not found...
pawn Код:
new pname2[24];
    GetPlayerName(playerid, pname2, sizeof(pname2));
    new found = strfind("[GC]", pname2);
    if(found != -1)
    {
        SendClientMessage(playerid, RED, "Found");
    }
    else
    {
        SendClientMessage(playerid, RED, "Not Found");
        }
Any help?
Reply
#2

I don't see anything wrong in the codes...maybe a better-eyed scripter will..
Try looking here.
Reply
#3

You have parameters messed up. You are trying to search for your name in tag [GC] and thats why it isnt working
https://sampwiki.blast.hk/wiki/Strfind

EDIT:
pawn Код:
new pname2[24];
GetPlayerName(playerid, pname2, sizeof(pname2));
if(strfind(pname2, "[GC]", false) != 1);
{
    SendClientMessage(playerid, RED, "Found");
}
else
{
    SendClientMessage(playerid, RED, "Not Found");
}
Reply
#4

I guess you got your answer.
Reply
#5

There's a good example in wikipedia.
The first parameter is the haystack and the second on is the needle.
Reply
#6

Macluawn while you think you're right, You're actually not, The compiler gave me no warning and if you look closer at the wiki you will see..

strfind(const string[],const sub[],bool:ignorecase=false,pos=0)

Notice how it automatically sets those last two parameters?

Anyone else?
Reply
#7

The first to parameters are both strings, so compiler doesn't show any erorrs.
And you can remove 'false' if you want to
The variable is removed, because it's more optimized without it.

So.. I'm right and you're not.
Reply
#8

@OP
No you're wrong

const string[] The string you want to search in (haystack).
const sub[] The string you want to search for (needle).
Reply
#9

haystack should be your name, and needle should be the tag. Not the other way around.
Reply
#10

Oh, I'll try that now, I was probably wrong about THAT but the other thing no I wasn't.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)