04.04.2010, 16:53
pawn Code:
/**
* Finds a word in a string
* @param string The string to search
* @param word The word to search for
* @param ignorecase If the search is case insensitive
* @param pos The starting position for the search
* @return The position in the string of the begining of the word, or -1 if not found
*/
stock strfindword(const string[], const word[], bool:ignorecase=false, pos=0)
{
if(isnull(word)) return -1;
new wlen = strlen(word);
if(ispacked(string)) {
for(new i = strfind(string, word, ignorecase, pos); i != -1; i = strfind(string, word, ignorecase, ++i)) {
if((i == 0 || string{i-1} <= ' ') && string{i+wlen} <= ' ') {
return i;
}
}
} else {
for(new i = strfind(string, word, ignorecase, pos); i != -1; i = strfind(string, word, ignorecase, ++i)) {
if((i == 0 || string[i-1] <= ' ') && string[i+wlen] <= ' ') {
return i;
}
}
}
return -1;
}