23.07.2011, 21:44
How do I make a function that can return the number of a certain character in a string? For example I want 'CountChars("~", string) to tell me how many ~'s are in string.
Thanks.
Thanks.
CountChars('~', string);
stock CountChars(ch, str[], len = sizeof(str))
{
new count;
for(new i; i != len; i++) if(str[i] == ch) count++;
return count;
}
stock CountChars(txt[],ch='~')
{
new d,cnt;
while(txt[d] != EOS)
{
if(txt[d] == ch) cnt++;
d++;
}
return cnt;
}