SA-MP Forums Archive
How to Compare if 2 strings are NOT equal? - 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)
+--- Thread: How to Compare if 2 strings are NOT equal? (/showthread.php?tid=605892)



How to Compare if 2 strings are NOT equal? - Ritzy2K - 26.04.2016

Ok, i want that if the string DOESN'T match, it should send this message, but with this code, it will send the message if the string matches right? Any idea how do i check about inequality with strcmp?

Код:
if(!strcmp(Faction_GetName(playerid), "S.W.A.T", true, 5))
	    return SendErrorMessage(playerid, "You're not S.W.A.T Member");



Re: How to Compare if 2 strings are NOT equal? - Konstantinos - 26.04.2016

Returns 0 if they're equal so check if it's not 0:
pawn Код:
if(strcmp(Faction_GetName(playerid), "S.W.A.T", true))
pawn Код:
if(strcmp(Faction_GetName(playerid), "S.W.A.T", true) != 0)



Re: How to Compare if 2 strings are NOT equal? - Lordzy - 26.04.2016

strcmp returns values other than 0 if they're not equal. So you can simply remove "!" from your strcmp's if statement or do as follow :
pawn Код:
if(strcmp(string, string2, true) != 0) {
    //not equal.
}
EDIT : Late.


Re: How to Compare if 2 strings are NOT equal? - Ritzy2K - 26.04.2016

Thanks a lot!

Edit: This shows tag mismatch warning?

Код:
if(!strcmp(Faction_GetName(playerid), "S.W.A.T", true) != 0)
	    return SendErrorMessage(playerid, "You are not a S.W.A.T Member");



Re: How to Compare if 2 strings are NOT equal? - Ritzy2K - 26.04.2016

It also doesn't work anymore the way it should. Works Vice-Versa.


Re: How to Compare if 2 strings are NOT equal? - Konstantinos - 26.04.2016

Quote:
Originally Posted by [ND]xXZeusXx.
Посмотреть сообщение
Thanks a lot!

Edit: This shows tag mismatch warning?

Код:
if(!strcmp(Faction_GetName(playerid), "S.W.A.T", true) != 0)
	    return SendErrorMessage(playerid, "You are not a S.W.A.T Member");
You can't use ! before strcmp and != 0 at the same time. Re-read the posts above.


Re: How to Compare if 2 strings are NOT equal? - Ritzy2K - 26.04.2016

Sorry, My bad.