AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Matching strings with wildcard in middle (https://forums.alliedmods.net/showthread.php?t=89190)

Emp` 04-03-2009 12:42

Matching strings with wildcard in middle
 
So.... I have the strings
Code:

new string[] = "pp_area_ent";
new match[] = "pp_%s_ent";

I need a function to behave like equali and so I have:
Code:

SmartEquali( const string[], match[], strcomp_len )
{
        new wildcard = containi( match, "%s" );
        // if no wildcard or wildcard is at end of string
        if( wildcard == -1 || (wildcard >= strcomp_len && strcomp_len > 0) ){
                if( strcomp_len != -1 ){
                        if( equali( string, match, strcomp_len ) )
                                return true;
                }
                else{
                        if( containi( string, match )!=-1 )
                                return true;
                }
                return false;
        }
        else{
                new match_start[32], match_end[32];
                copy( match_start, 31, match );
                match_start[wildcard] = 0;
                copy( match_end, 31, match[wildcard+2] );
                return (SmartEquali( string, match_start, wildcard ) && SmartEquali( string, match_end, -1 ))
        }
        return false;
}

Anyone see problems with it? (Haven't been able to test it)


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

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