Please enable JavaScript to view this site.

thinBasic Help Manual

* * HELP & MANUAL PREMIUM PACK 4 DEMO VERSION * *

This documentation was styled with a demo skin from the Premium Pack 4 add-on for Help & Manual. The contents of the skin are encrypted and not configurable. You can only publish HM projects with this skin. You cannot edit it or change it.

This version is copyright and may only be used for local testing purposes. It may not be distributed.

Please purchase the full version of the Premium Pack to get the configurable skins and remove this notice. The package will also include the Toolbox configuration utility for Premium Pack skins.

 

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

 

String Handling,

 

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

 

 

 

Created with Help+Manual 8 and styled with Premium Pack Version 4 © by EC Software