Array - how can I skip a repeated value in an array?
#7

Quote:
Originally Posted by IstuntmanI
Посмотреть сообщение
This is the best method I could think of:
pawn Код:
new bool:continueLoop = true;

for (new x = 0; x < sizeof(datatesting); x++)
{
    for (new xx = 0; xx < x; xx++)
    {
        if (strfind(datatesting[xx][dmCategory], datatesting[xx][dmCategory]) == 0) // strfind is faster than strcmp
        {
            continueLoop = false; // we can't break here the main loop, so we set our variable as false
            break; // already found a duplicate, stop this duplicate-detector loop !
        }
    }

    if (continueLoop == false) // if a duplicate one was detected, continue our loop
    {
            continueLoop = true;
            continue;
    }

    format(string, sizeof(string), "%s\t%d\n",datatesting[x][dmCategory],x);
    strcat(fullstr, string);
}
Quote:
Originally Posted by Pottus
Посмотреть сообщение
How about...

Код:
for (new x = 0; x < sizeof(datatesting)-1; x++)
{
	if(strlen(datatesting[x][dmCategory]) < 1) continue;
	for (new xx = x+1; xx < x; xx++)
	{
		if(strlen(datatesting[xx][dmCategory]) < 1) continue;
		if (strfind(datatesting[x][dmCategory], datatesting[xx][dmCategory]) == 0) // strfind is faster than strcmp
		{
			continueLoop = false; // we can't break here the main loop, so we set our variable as false
			break; // already found a duplicate, stop this duplicate-detector loop !
		}
	}

	if (continueLoop == false) // if a duplicate one was detected, continue our loop
	{
			continueLoop = true;
			continue;
	}

	format(string, sizeof(string), "%s\t%d\n",datatesting[x][dmCategory],x);
	strcat(fullstr, string);
}
Quote:
Originally Posted by Juand
Посмотреть сообщение
Hello, the one provided by IstuntmanI works by changing
pawn Код:
if (strfind(datatesting[xx][dmCategory], datatesting[xx][dmCategory]) == 0)
for...
if (strfind(datatesting[x][dmCategory], datatesting[xx][dmCategory]) == 0)
using strfind in the place of strcmp is not a good idea as strfind might return 0 for strings like this
PHP код:
"Help me man " and "Help me" 
so both of the code will not work in such conditions.(However pottus' code wont work in any cases (for (new xx = x+1; xx < x; xx++)
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)