SA-MP Forums Archive
STRFIND not working? - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: STRFIND not working? (/showthread.php?tid=275941)



STRFIND not working? - [WF]Demon - 11.08.2011

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?


Re: STRFIND not working? - Darnell - 11.08.2011

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


Re: STRFIND not working? - Macluawn - 11.08.2011

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");
}



Re: STRFIND not working? - Darnell - 11.08.2011

I guess you got your answer.


Re: STRFIND not working? - Macluawn - 11.08.2011

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


Re: STRFIND not working? - [WF]Demon - 11.08.2011

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?


Re: STRFIND not working? - Macluawn - 11.08.2011

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.


Re: STRFIND not working? - PrawkC - 11.08.2011

@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).


Re: STRFIND not working? - Macluawn - 11.08.2011

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


Re: STRFIND not working? - [WF]Demon - 11.08.2011

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