Raised This Month: $ Target: $400
 0% 

Problem with containi function


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
itimeheke
Junior Member
Join Date: Dec 2010
Old 01-04-2011 , 15:09   Problem with containi function
Reply With Quote #1

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;
    


Last edited by itimeheke; 01-04-2011 at 15:13.
itimeheke is offline
.MMYTH.
BANNED
Join Date: Sep 2010
Location: Brasil - RS
Old 01-04-2011 , 15:56   Re: Problem with containi function
Reply With Quote #2

why use containi?
use contain
.MMYTH. is offline
Send a message via MSN to .MMYTH.
itimeheke
Junior Member
Join Date: Dec 2010
Old 01-04-2011 , 15:57   Re: Problem with containi function
Reply With Quote #3

Cuz i'd want it to be case insensitive. Is there any difference? If so, i can lower both strings and then contain?
itimeheke is offline
.MMYTH.
BANNED
Join Date: Sep 2010
Location: Brasil - RS
Old 01-04-2011 , 15:59   Re: Problem with containi function
Reply With Quote #4

is this a sensitive case ?
.MMYTH. is offline
Send a message via MSN to .MMYTH.
itimeheke
Junior Member
Join Date: Dec 2010
Old 01-04-2011 , 16:01   Re: Problem with containi function
Reply With Quote #5

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 is offline
itimeheke
Junior Member
Join Date: Dec 2010
Old 01-04-2011 , 16:09   Re: Problem with containi function
Reply With Quote #6

Figured out! I forgot that its returning position of the string, or -1 as not found, so it may be zero also. Thanks anyway!
itimeheke is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-04-2011 , 16:12   Re: Problem with containi function
Reply With Quote #7

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
__________________
Bugsy is offline
itimeheke
Junior Member
Join Date: Dec 2010
Old 01-04-2011 , 16:13   Re: Problem with containi function
Reply With Quote #8

Yeah, figured it out already, thanks any way bugsy
itimeheke is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-04-2011 , 21:00   Re: Problem with containi function
Reply With Quote #9

Quote:
Originally Posted by itimeheke View Post
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 .
__________________
fysiks is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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