[QUESTION] How do I check if one string equals to another one?
#1

How do I check if one string equals to another one?

thanks,
Reply
#2

https://sampwiki.blast.hk/wiki/Strcmp
Reply
#3

pawn Код:
if(string1 == string2) {
//dothis
} else {
//dothis
}
Reply
#4

thx MadeMan,

and jameskmonger, this thing used only for numbers no?
Reply
#5

Quote:
Originally Posted by borisblat
thx MadeMan,
and jameskmonger, this thing used only for numbers no?
Right.
Reply
#6

^^
well I used strcmp, here is the code|:
Код:
			 for(new id = 1; id<=MAX_CLANS; id++)
			 {
				 clanname = GetClanName(id);
				 format(cfile, sizeof(cfile), "Blat/Clans/%s.txt", clanname);
				 unionname2 = dini_Get(cfile, "Union");
				 if(strcmp(unionname2,unionname, true) == 0)
			     dini_Unset(cfile, "Union");
			 }
and it do crash to the filterscript what's wrong

here is the GetClanName if needed
Код:
stock GetClanName(clanid)
{
	new file[256], clanname[256];
	format(file, sizeof(file), "Blat/Clans/IDs/%d.txt", clanid);
	clanname = dini_Get(file, "Name");
	return clanname;
}
Reply
#7

Quote:
Originally Posted by borisblat
and jameskmonger, this thing used only for numbers no?
What do you mean?
Reply
#8

Quote:
Originally Posted by jameskmonger
What do you mean?
He means that your code is wrong if you want to compare the two strings.
Quote:
Originally Posted by jameskmonger
pawn Код:
if(string1 == string2) {
//dothis
} else {
//dothis
}
With this, you could compare integers (numbers).
Reply
#9

Quote:
Originally Posted by Don Correlli
Quote:
Originally Posted by jameskmonger
What do you mean?
He means that your code is wrong if you want to compare the two strings.
Quote:
Originally Posted by jameskmonger
pawn Код:
if(string1 == string2) {
//dothis
} else {
//dothis
}
With this, you could compare integers (numbers).
Can't you compare strings? (I'm used to Java xD)
Reply
#10

Quote:
Originally Posted by jameskmonger
Can't you compare strings? (I'm used to Java xD)
No, you need to use the strcmp function.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)