Compare two string -
Kyra - 20.07.2012
Hello, I use a timer to display textdraw, i wish does not reuse the function when the string is the same as previously
But I dont know how to compare two string
Example
Code:
new string[128];
new oldstring[128];
if(string != oldstring)// not correct
AW: Compare two string -
dalkgamler - 20.07.2012
i think you have to use if(!strcmp(string, oldstring)
Re: Compare two string -
EV007 - 20.07.2012
#define equal(%0,%1) !strcmp(%0,%1,false) && strlen(%0) == strlen(%1)
if(equal(string,string2))
enjoy.
Re : Compare two string -
Kyra - 20.07.2012
Nice!
But if u want compare if the two string are different ?
Code:
#define equal(%0,%1) !strcmp(%0,%1,false) && strlen(%0) != strlen(%1)
Its correct or not?
Re: Compare two string -
EV007 - 20.07.2012
if(!equal(string,string2))
note the ! on beginning
Re: Compare two string -
TheArcher - 20.07.2012
Just use the same macro that EV007 have put. So to compare two different strings just do.
if(!equal(string,string2)) etc...
Edit: Duh EV007 was faster than me
Re : Compare two string -
Kyra - 20.07.2012
Thanks for your help!! But why doesnt work ?
My code
Code:
new stringstats2[MAX_PLAYERS][128];
new oldstringstats2[MAX_PLAYERS][128];
format(stringstats2[i], sizeof(stringstats2), "Kills: %d ~n~Deaths: %d ~n~Ratio: %.2f ~n~Ratio Duel: %.2f",PlayerInfo[i][pKills],PlayerInfo[i][pDeaths],Float:PlayerInfo[i][pKills]/Float:PlayerInfo[i][pDeaths],Float:PlayerInfo[i][pDuelWin]/Float:PlayerInfo[i][pDuelLoose]);
if(!equal(stringstats2[i],oldstringstats2[i]))
{
TextDrawSetString(textdrawstats2[i], stringstats2[i]);
TextDrawShowForPlayer(i,textdrawstats2[i]);
format(oldstringstats2[i], sizeof(oldstringstats2), "Kills: %d ~n~Deaths: %d ~n~Ratio: %.2f ~n~Ratio Duel: %.2fs",PlayerInfo[i][pKills],PlayerInfo[i][pDeaths],Float:PlayerInfo[i] [pKills]/Float:PlayerInfo[i][pDeaths],Float:PlayerInfo[i][pDuelWin]/Float:PlayerInfo[i][pDuelLoose]);
SendClientMessageToAll(-1,"test");
}
Re: Compare two string -
Roko_foko - 20.07.2012
Be more specific!
What does not work?
What do you want this code to do?
What it actually do?
Does it give you some warnings/errors?
Re : Compare two string -
Kyra - 20.07.2012
Hum i not have warnings and erros
I want not reuse the function
"TextDrawSetString(textdrawstats2[i], stringstats2[i]); etc..." when the string is the same as previously to optimize my script
the script stops at
"if(!equal(stringstats2[i],oldstringstats2[i]))"
Re : Compare two string -
Kyra - 21.07.2012
Code:
if(strcmp(string1,string2, true) == 0) // string 1 and string 2 are same
But thx for ur help