Results 1 to 3 of 3

Thread: about TALLY function

  1. #1

    about TALLY function

    i was about to ask a new feature like this
    n = Tally(txt, Any "A" | "b" | "z")
    does not work
    then tried
    n = Tally(txt, Any ("A" , "b" , "z"))
    does not work
    then searching the examples for the word "any", most of the results is "press any key to end"
    then fortunately i saw "any $spc & $tab & $nul)" in example ODBC_EX_03, and i said thats it let me try again, and now it works
    n = Tally(txt, Any "A" & "o" & "B" & "i" &"I" )
    n = Tally(txt, Any "A" + "o" + "B" + "i" +"I" )
    the two versions works
    so my problem solved .
    there is a famous basic programming language which have
    CountString(txt, "a")
    but seems not possible like in thinbasic, it does not accept multichoices inside CountString.
    Uses "Console"
    String txt 
    DWord n
    txt = "Hello World from ThinBASIC!" 
    n = Tally(txt, Any "A" & "o" & "B" & "i" &"I" )
    'n = Tally(txt, Any "A" + "o" + "B" + "i" +"I" )
    '---Print the magic words
    PrintL "Hello World from ThinBASIC!"
    PrintL "number of characters AoBiI in the above phrase = " + Str$(n)
    PrintL "Press a key to end program"
    '---Wait for a key press
    WaitKey
    

  2. #2
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,530
    Rep Power
    171
    as simple as
    n = Tally(txt, Any "AoBiI" )
    


    to count single chars or continuing occurences in same order you also could "abuse" ParseCount-function.
    subtract 1 since the result usually tells the count of text-parts delimited by the passed chars

    Uses "Console"
    
    String txt = "Hello World from ThinBASIC!"
    PrintL txt & $CRLF
    
    PrintL "Tally      ""ThinBASIC!""     = ", Str$(Tally(txt, "ThinBASIC!"))
    PrintL "Tally Any  ""ThinBASIC!""     = ", Str$(Tally(txt, Any "ThinBASIC!")) 
    PrintL "Parsecount ""ThinBASIC!"" - 1 = ", Str$(ParseCount(txt, "ThinBASIC!" )-1)
    
    
    PrintL $CRLF & "key to end"
    WaitKey
    
    Last edited by ReneMiner; 16-02-2016 at 12:48.
    I think there are missing some Forum-sections as beta-testing and support

  3. #3
    you are right ReneMiner , and thanks, just 3 minutes ago i said to myself why this
    n = Tally(txt, Any "AoBiI" ) does not come to my mind, i should go to the forum and edit the code .
    possibly (and not sure) my hidden idea was a general form which accepts also something like this
    n = Tally(txt, Any "He" , "T") ie searching "He" as a whole and "T"
    even we could do this using other string functions. the Tally is small and handy to use

Similar Threads

  1. [Q]: Function f() PTR?
    By ReneMiner in forum thinBasic General
    Replies: 3
    Last Post: 18-07-2013, 20:29
  2. Gamma function
    By danbaron in forum Math: all about
    Replies: 14
    Last Post: 08-08-2011, 03:51
  3. Wait function
    By peralta_mike in forum thinBasic General
    Replies: 4
    Last Post: 06-07-2010, 04:41
  4. function returned value
    By sandyrepope in forum thinBasic General
    Replies: 4
    Last Post: 07-12-2007, 22:54
  5. Usage of TALLY Keyword
    By Michael Clease in forum Samples for help file
    Replies: 1
    Last Post: 29-05-2007, 15:40

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •