Jump to content

[Tutorial] Functii customizate: strcontain, strcasecontain


Recommended Posts

Guest claudiuhks
Posted

strcasecontain intoarce true daca ccSubString este inclusa in ccString fara a tine cont de dimensiunea literelor!

strcontain intoarce true daca ccSubString este inclusa in ccString tinand cont de dimensiunea literelor!



bool strcasecontain( const char *ccString, const char *ccSubString )
{
const char *ccCopyOfString = ccString, *ccSecondCopyOfString = ccString, *ccCopyOfSubString = ccSubString, *ccSecondCopyOfSubString = ccSubString;

while( *ccSecondCopyOfString )
{
if( tolower( *ccSecondCopyOfString ) == tolower( *ccCopyOfSubString ) )
{
ccSecondCopyOfString++;

if( !*++ccCopyOfSubString )
return true;
}

else
ccSecondCopyOfString = ++ccCopyOfString, ccCopyOfSubString = ccSecondCopyOfSubString;
}

return false;
}


bool strcontain( const char *ccString, const char *ccSubString )
{
const char *ccCopyOfString = ccString, *ccSecondCopyOfString = ccString, *ccCopyOfSubString = ccSubString, *ccSecondCopyOfSubString = ccSubString;

while( *ccSecondCopyOfString )
{
if( *ccSecondCopyOfString == *ccCopyOfSubString )
{
ccSecondCopyOfString++;

if( !*++ccCopyOfSubString )
return true;
}

else
ccSecondCopyOfString = ++ccCopyOfString, ccCopyOfSubString = ccSecondCopyOfSubString;
}

return false;
}

Guest claudiuhks
Posted

Iata si un exemplu:


int main( )
{
if( strcasecontain( "NewLifeZM.CsBlackDevil.Com [Zombie Plague]", "newLifeZM.CsBlackDevil.Com" ) )
{
/* "NewLifeZM.CsBlackDevil.Com [Zombie Plague]" contains string "newLifeZM.CsBlackDevil.Com" (without quotes) -- ignoring the characters size */
}

return 1;
}

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.