TALLY returns the number of times Match occurs in MainStr
Syntax:RetVal = TALLY(MainStr AS STRING, Match AS STRING [,CaseSensitivity AS INTEGER]) Return Value:
Parameters: |
This snippet uses the TALLY function default case sensitive mode.
DIM a$ DIM b$ DIM int1% a$ = " ABC abc AbC aBc " b$ = "abc" int1% = TALLY(a$, b$) PRINT int1%
1
This snippet uses the TALLY function optional case insensitive mode.
DIM a$ DIM b$ DIM int1% a$ = " ABC abc AbC aBc " b$ = "abc" int1% = TALLY(a$, b$, 1) PRINT int1%
4
This example uses the TALLY function to count linefeed characters from a buffered file.
PRINT FileLineCount("bc.bas") FUNCTION FileLineCount (Filename$) AS LONG LOCAL FF AS FILE ' local file name that we'll use LOCAL Linefeeds ' accumulate the line feeds in the text file LOCAL Buff$ * 16384 ' 16k reusable buffer IF EXIST(Filename$) = 0 THEN EXIT FUNCTION OPEN Filename$ FOR BINARY AS FF WHILE NOT EOF(FF) GET$ FF, Buff$, 16384 Linefeeds += TALLY(Buff$, LF$) memset(Buff$, 0, 16384) WEND CLOSE FF FUNCTION = Linefeeds END FUNCTION