[HELP] Finding whole words in a string?
#7

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;
}
Reply


Messages In This Thread
[HELP] Finding whole words in a string? - by Ibanez - 04.04.2010, 12:45
Re: [HELP] Finding whole words in a string? - by Jefff - 04.04.2010, 12:54
Re: [HELP] Finding whole words in a string? - by Ibanez - 04.04.2010, 13:08
Re: [HELP] Finding whole words in a string? - by WackoX - 04.04.2010, 13:13
Re: [HELP] Finding whole words in a string? - by Ibanez - 04.04.2010, 13:19
Re: [HELP] Finding whole words in a string? - by Beaver07 - 04.04.2010, 16:50
Re: [HELP] Finding whole words in a string? - by Dabombber - 04.04.2010, 16:53

Forum Jump:


Users browsing this thread: 1 Guest(s)