String in if() statements
#1

How can I add stirng in 'if' statements?

I am trying to check if a certain var contains 'None'...
Reply
#2

Can you please tell a bit more clearly actually what your wanting?
Reply
#3

wiki.sa-mp.com/wiki/strcmp
Example:
pawn Код:
new Lname[MAX_PLAYER_NAME];
GetPlayerName(playerid, Lname, sizeof(Lname));
if(!strcmp(Lname, "None", true)) return SendClientMessageToAll(-1, "None");
Reply
#4

The thing is, am looking for something like this:

if(hInfo[h][hOwner] == "None")
{
CreateObject(blah blah);
}
Reply
#5

use strfind function

if(!strfind(string,"None", true))
Reply
#6

Quote:
Originally Posted by ikey07
Посмотреть сообщение
use strfind function

if(!strfind(string,"None", true))
Ah never though of that, thanks ikey
Reply
#7

Quote:
Originally Posted by Riddy
Посмотреть сообщение
Ah never though of that, thanks ikey
No, for the reason you need it - use strcmp(like in the example above).
Reply
#8

Quote:
Originally Posted by wups
Посмотреть сообщение
No, for the reason you need it - use strcmp(like in the example above).
I dont see why I should use strcmp, considering am only looking for 'None' in the variables hInfo[h][hOwner]...

if(strfind(hInfo[h][hOwner], "None", true)), this looks for 'None' in the variables as for as I know...
Reply
#9

What the hell is the problem with you? If your property does not have an owner, make the string "*" by simply assigning the value (no format, no strcat, no whatsoever, just simply = to assign).
To check if the property is unowned, do if(hInfo[h][hOwner][0] == '*'). Simple and quick, voila.

And there's really nothing to justify using strfind instead of strcmp if you've designed the system yourself and are aware of the array contents
Reply
#10

Quote:
Originally Posted by AndreT
Посмотреть сообщение
What the hell is the problem with you? If your property does not have an owner, make the string "*" by simply assigning the value (no format, no strcat, no whatsoever, just simply = to assign).
To check if the property is unowned, do if(hInfo[h][hOwner][0] == '*'). Simple and quick, voila.

And there's really nothing to justify using strfind instead of strcmp if you've designed the system yourself and are aware of the array contents
The thing is, I never made the system, but I know whats the data suppose to be.. and am just looking if 'None' is in there and yes am wrong, I should be using strcmp not strfind.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)