diff --git a/plugins/include/string.inc b/plugins/include/string.inc index bfd1039b..9ff75eed 100644 --- a/plugins/include/string.inc +++ b/plugins/include/string.inc @@ -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. *