added amb1694 - FindCharInString()

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%402174
This commit is contained in:
David Anderson 2008-05-24 05:02:35 +00:00
parent dea6b06e2c
commit 2a11739e86

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.
*