1.1 --- a/plugins/include/string.inc Sat May 24 04:08:29 2008 +0000
1.2 +++ b/plugins/include/string.inc Sat May 24 05:02:35 2008 +0000
1.3 @@ -422,6 +422,46 @@
1.4 }
1.5
1.6 /**
1.7 + * Finds the first occurrence of a character in a string.
1.8 + *
1.9 + * @param str String.
1.10 + * @param c Character to search for.
1.11 + * @param reverse False (default) to search forward, true to search
1.12 + * backward.
1.13 + * @return The index of the first occurrence of the character
1.14 + * in the string, or -1 if the character was not found.
1.15 + */
1.16 +stock FindCharInString(const String:str[], c, bool:reverse = false)
1.17 +{
1.18 + new i, len
1.19 +
1.20 + len = strlen(str);
1.21 +
1.22 + if (!reverse)
1.23 + {
1.24 + for (i = 0; i < len; i++)
1.25 + {
1.26 + if (str[i] == c)
1.27 + {
1.28 + return i;
1.29 + }
1.30 + }
1.31 + }
1.32 + else
1.33 + {
1.34 + for (i = len - 1; i >= 0; i--)
1.35 + {
1.36 + if (str[i] == c)
1.37 + {
1.38 + return i;
1.39 + }
1.40 + }
1.41 + }
1.42 +
1.43 + return -1;
1.44 +}
1.45 +
1.46 +/**
1.47 * Concatenates one string onto another.
1.48 *
1.49 * @param buffer String to append to.