added amb1694 - FindCharInString

--HG--
branch : sourcemod-1.0.x
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/branches/sourcemod-1.0.x%402206
This commit is contained in:
David Anderson 2008-05-29 03:46:42 +00:00
parent a628f370e4
commit d2cfd39f80

View File

@ -421,6 +421,46 @@ stock CharToLower(chr)
return chr;
}
/**
* Finds the first occurrence of a character in a string.
*
* @param str String.
* @param c Character to search for.
* @param reverse False (default) to search forward, true to search
* backward.
* @return The index of the first occurrence of the character
* in the string, or -1 if the character was not found.
*/
stock FindCharInString(const String:str[], c, bool:reverse = false)
{
new i, len
len = strlen(str);
if (!reverse)
{
for (i = 0; i < len; i++)
{
if (str[i] == c)
{
return i;
}
}
}
else
{
for (i = len - 1; i >= 0; i--)
{
if (str[i] == c)
{
return i;
}
}
}
return -1;
}
/**
* Concatenates one string onto another.
*