30.12.2014, 15:23
CountWord
This function will return the number of times the given word has been repeated in a string.
Example:
The above code will print "2 times" because ignorecase is set to false. If it was set to true, it would've printed "4 times".
This function will return the number of times the given word has been repeated in a string.
pawn Код:
stock CountWord(string[], word[], bool:ignorecase = false)
{
new
temp_Counts = 0,
temp_Pos = -1;
temp_Pos = strfind(string, word, ignorecase, 0);
while(temp_Pos != -1)
{
temp_Counts++;
temp_Pos = strfind(string, word, ignorecase, temp_Pos + strlen(word) - 1);
}
return temp_Counts;
}
pawn Код:
new
string[] = {"This is a string, this string contains something. This is something and this will be found!"};
printf("%d times", CountWord(string, "This", false);