strcount function?
#1

Is there a command out there that can can:
-Count the amount of characters given as in a input in a string

Example:
pawn Код:
new string[128], count;
format(string, sizeof(string), "341,141,514,141");
count = strcount(string, ",");
print(count);
OUTPUT: 3

Can anyone help me make a function like that..?
Reply
#2

pawn Код:
str_countcharacters(str[], char)
{
    new c;
    for(new i, l = strlen(str); i < l; i++)
        if(str[i] == char)
            c++;
    return c;
}
Not tested, but should work

Example:
pawn Код:
printf("%d", str_countcharacters("341,141,514,141", ','));
Reply
#3

Quote:
Originally Posted by ziomal432
pawn Код:
str_countcharacters(str[], char)
{
    new c;
    for(new i, l = strlen(str); i < l; i++)
        if(str[i] == char)
            c++;
    return c;
}
Not tested, but should work

Example:
pawn Код:
printf("%d", str_countcharacters("341,141,514,141", ','));
Thanks! It works!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)