Compare two string
#1

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
Reply
#2

i think you have to use if(!strcmp(string, oldstring)
Reply
#3

#define equal(%0,%1) !strcmp(%0,%1,false) && strlen(%0) == strlen(%1)

if(equal(string,string2))

enjoy.
Reply
#4

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?
Reply
#5

if(!equal(string,string2))

note the ! on beginning
Reply
#6

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
Reply
#7

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

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?
Reply
#9

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]))"
Reply
#10

Code:
if(strcmp(string1,string2, true) == 0) // string 1 and string 2 are same
But thx for ur help
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)