Navigation: thinBasic Modules > Core > String handling > TALLY |
|
Description
Count the number of occurrences of specified characters or strings within a string.
Syntax
n = TALLY(MainString, [ANY] MatchString)
Returns
Number
Parameters
Name |
Type |
Optional |
Meaning |
MainString |
String |
No |
Is the string expression in which to count characters |
MatchString |
String |
No |
If the ANY keyword is included, MatchString specifies a list of single characters to be searched for individually: a match on any one of which will cause the count to be incremented for each occurrence of that character. |
Remarks
Restrictions
See also
Examples
Thanks to Abraxas for the following script example
' Usage of Tally Keyword
Dim MainString As String VALUE "HELLO a bb cc WORLD"
Dim LowerAlpha(26) As Byte
Dim UpperAlpha(26) As Byte
Dim count As DWORD
Dim sMsg As String
sMsg = " Character Count" & $CRLF & $CRLF
sMsg += "CHAR" & $Tab & "UPPER" & $Tab & "LOWER" & $CRLF & $CRLF
'Count Characters and Display the counts
For count = 1 To 26
Loweralpha(count) = TALLY(MainString, Any chr$(count + 64)) ' 65 is ascii 'A'
Upperalpha(count) = TALLY(MainString, Any chr$(count + 96)) ' 97 is ascii 'a'
sMsg += CHR$(count + 64) & " & " & CHR$(count + 96) & $Tab
sMsg += " " & Loweralpha(count) & $Tab
sMsg += " " & Upperalpha(count) & $CRLF
Next
MSGBOX 0, sMsg
© 2004-2008 thinBasic. All rights reserved. | Version 1.7.0.0 | Web Site: http://www.thinbasic.com |