AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Problem with containi function (https://forums.alliedmods.net/showthread.php?t=147040)

itimeheke 01-04-2011 15:09

Problem with containi function
 
Hi there!

I'm using containi on my function which searches users by name. And it does not work, it passes like even "Alfred" compared to "elli" (TESTED!). This is my code:
PHP Code:

public players_find(szInput[], iPlayersFound[32]) {
    
    if (
strlen(szInput) == 0)
        return 
0;
        
    new 
iPlayers[32];
    new 
iPlayersCountiPlayersFoundCount;
    
get_players(iPlayersiPlayersCount);
    
    for (new 
iiPlayersCounti++ ) {
        new 
szName[32];
        
get_user_name(iPlayers[i], szName31);

        if (
containi(szNameszInput)) {
            
client_print(0print_chat"%s = %s"szInputszName);
            
iPlayersFound[iPlayersFoundCount] = iPlayers[i];
            
iPlayersFoundCount++;
        }
    }
    
    return 
iPlayersFoundCount;
    



.MMYTH. 01-04-2011 15:56

Re: Problem with containi function
 
why use containi?
use contain

itimeheke 01-04-2011 15:57

Re: Problem with containi function
 
Cuz i'd want it to be case insensitive. Is there any difference? If so, i can lower both strings and then contain?

.MMYTH. 01-04-2011 15:59

Re: Problem with containi function
 
is this a sensitive case ?

itimeheke 01-04-2011 16:01

Re: Problem with containi function
 
From string.inc:
PHP Code:

/* Checks if source contains string. On success function
* returns position in source, on failure returns -1. */
native contain(const source[],const string[]);

/* Checks if source contains string with case ignoring. On success function
* returns position in source, on failure returns -1. */
native containi(const source[],const string[]); 

This says containi is not, so i assume that contain is, but i'll check that to be sure, thanks for idea:)

itimeheke 01-04-2011 16:09

Re: Problem with containi function
 
Figured out! :D I forgot that its returning position of the string, or -1 as not found, so it may be zero also. Thanks anyway!

Bugsy 01-04-2011 16:12

Re: Problem with containi function
 
contain is case sensitive, containi is not.

They both return the position in the string if the substring is found; It returns -1 if the substring is not found.

You should use:

if ( containi( ) > -1 )

edit: a little late on the reply as I was typing on my phone :-P

itimeheke 01-04-2011 16:13

Re: Problem with containi function
 
Yeah, figured it out already, thanks any way bugsy :)

fysiks 01-04-2011 21:00

Re: Problem with containi function
 
Quote:

Originally Posted by itimeheke (Post 1386110)
Yeah, figured it out already, thanks any way bugsy :)

Don't feel bad because most of us have been trapped by that. The function doesn't work as logic would tell us :).


All times are GMT -4. The time now is 02:13.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.