Announcement

Collapse
No announcement yet.

Question on PARSECOUNT

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Question on PARSECOUNT

    Oh, am I on a roll.

    Now I have a question on PARSECOUNT. The help file states;
    ...the delimiter itself is never returned as part of the field.
    However, one of the examples is:
    a& = PARSECOUNT("xx1x","x") ' returns 4
    Now if there are three "x"'s in main string, how can a& return
    a 4 unless string_delimiter is included in the count?

    or am I confused again?


    ------------------
    There are no atheists in a fox hole or the morning of a math test.
    If my flag offends you, I'll help you pack.

  • #2
    The same as if there were three commas:

    x,x,1,x

    This is how I believe parsecount is counting that string:

    [1]x[2]x[3]1x[4]

    ------------------
    Adam Drake
    PowerBASIC

    Comment


    • #3
      There was a thread on this some time back (before PB/Win 8). PARSECOUNT always returns a minimum of 1, even on a null string.

      ------------------
      --
      <strong>Billing clients for your freelance work?</strong> Try <a href="http://www.minute-2-minute.com">Minute-2-Minute</a>, the project management, timing, and billing system. Perfect for programmers who charge by the hour. FREE 45-day trial.

      Comment


      • #4
        If you just want to count the delimeters then use Tally(), parsecount counts the fields so if there is one "X" then it will return "2" as there is a field on either side of the "X".

        Basically Parsecount = Tally + 1

        Not that simple under the hood though of course as parsecount handles CSV quoted string etc too

        ------------------
        Paul Dwyer
        Network Engineer
        Aussie in Tokyo

        Comment


        • #5
          Well, Paul, Borge and I had a go-around about TALLY via e-mail.
          The short version is that, under certain circumstances, TALLY
          returns incorrect results.

          That's why I am looking for something other than INSTR to count
          occurances in a string but so far, INSTR is the most accurate I
          have been able to use.


          ------------------
          There are no atheists in a fox hole or the morning of a math test.
          If my flag offends you, I'll help you pack.

          Comment


          • #6
            I would be VERY interested to hear about a circumstance that Tally returns bad results.

            please tell

            ------------------
            Paul Dwyer
            Network Engineer
            Aussie in Tokyo

            Comment


            • #7
              Both Tally and Parsecount works 100% correct. No bad results known,
              but must remember how a correct search is performed, by moving ahead
              with LEN(search) characters. This means that counting "xx" in string
              "xxx" returns 1 found occurrence and counting " x " in string " x x "
              also returns 1 found, since the search moves forward with LEN(search).

              Tally returns a 0-based result and ParseCount 1-based to match Parse$,
              as documented in PB Help.


              ------------------
              PowerBASIC Staff
              ------------------
              Private web-site: http://www.tolkenxp.com/pb
              Free downloads: POFFS, incLean, PBcodec, custom controls and PB samples.

              Comment


              • #8
                Well, okay. It was during the Bible12 contest that I ran across
                this.

                Quotes are shown here for illustrative purposes only but both
                MainString and MatchString have leading/trailing spaces. Without
                both spaces, it would find "void" in "avoid" and that's not
                what I wanted.

                What I would do is count a word then remove the word from the
                main string. Sooner or later, I would wind up with a main string
                of, for example (all words separated by a single space)

                " and and and God then that and "

                Looking for and counting the word " and " TALLY would find the
                1st, 3rd and last one. It would skip the 2nd " and " and, as
                Borge informed me, there's a reason.

                After TALLY finds the 1st occurance, it would skip the pointer
                ahead (len(MatchString)) (in this case, 5) and the pointer would
                then be pointing to the letter "a" on the 2nd occurance. Hence,
                it would not find the 2nd occurance.

                The fix to this was to replace all occurances of a single space
                with two spaces but this proved to really bog down the program
                and was too inefficient.

                Guess I'll stick with INSTR at least for the time being.


                ------------------

                After reading Borje's reply: I really don't want to P-U-O but
                TALLY and PARSECOUNT will return accurate values ONLY if the
                programmer understands what's going on and makes use of that
                understanding. Sometimes, the help file is a little vague on the
                why's-n-what-for's especially for someone who's new to the language.




                [This message has been edited by Mel Bishop (edited May 11, 2005).]
                There are no atheists in a fox hole or the morning of a math test.
                If my flag offends you, I'll help you pack.

                Comment


                • #9
                  > Sometimes, the help file is a little vague

                  I agree with you there - the documentation can always be improved and it's
                  very valuable to hear from users so we learn what to improve. Thanks, Mel!


                  ------------------
                  PowerBASIC Staff
                  ------------------
                  Private web-site: http://www.tolkenxp.com/pb
                  Free downloads: POFFS, incLean, PBcodec, custom controls and PB samples.

                  Comment


                  • #10
                    I really don't want to P-U-O but TALLY and PARSECOUNT will return accurate values ONLY if the programmer understands what's going on and makes use of that understanding
                    I believe this observation applies to more than TALLY and PARSECOUNT.

                    Or, to be more semantically correct...the answer to, "what <U>is</U> the correct and accurate value?" depends on such understanding.


                    Michael Mattias
                    Tal Systems (retired)
                    Port Washington WI USA
                    [email protected]
                    http://www.talsystems.com

                    Comment

                    Working...
                    X