Announcement

Collapse
No announcement yet.

Parsing Question

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

  • Parsing Question

    Greetings!

    I'm having a few problems with parsing. I've a handful of lines similar to this one:

    "You earn 58 experience points and find 43 gold pieces."

    ...that I'm attempting to parse. I'd like to end with two variables after parsing this line:

    XP&=58
    GP&=43

    What's the easiest way to pull a variable number from this set sentence?


    ------------------
    Don Ewald
    mailto:[email protected][email protected]</A>
    Donnie Ewald
    [email protected]

  • #2
    I'm not sure the parse function is what you need - I don't believe
    that there is a parse$ function in PBDOS.

    In PBCC or PBDLL you could parse it like this

    xp& = VAL(PARSE$(linetext$, ANY " ", 3))

    Using the spaces between the words as delimiters

    However, to accomplish the same thing in PBDOS you could
    use mid$ to strip just the numbers out of the sentence with MID$.
    (that is as long as the sentence was the same every time)

    xp& = val(MID$(linetext$,10,3))

    Neil Bertz
    ________________
    PowerBASIC Staff


    Comment


    • #3
      Depends on what you need to parse, how. On the assumption that you're
      just trying to pull the numbers from a sentence of this type, though, I'd
      be inclined to keep it simple:

      Code:
      s$ = "You earn 58 experience points and find 43 gold pieces."
      i% = instr(s$, any "0123456789")
      xp& = val(mid$(s$, i%))
      i% = instr(i% + len(str$(xp&)), s$, any "0123456789")
      gp& = val(mid$(s$, i%))
      ------------------
      Tom Hanlin
      PowerBASIC Staff

      Comment


      • #4
        Greetings!

        I do appreciate the replies given and the suggestion by Mr. Hanlin is golden! I was heading down a path similar to the suggestion by Mr. Bertz; but, I figured that there had to be an easier method.

        I can just imagine two different approaches to getting to the other side of a pole. My way, where I keep butting my head against the pole trying to get through because I know no better or someone pointing out that I can just walk around it.

        Sometimes, in my programming, I feel the same. Many thanks, Tom!


        ------------------
        Don Ewald
        mailto:[email protected][email protected]</A>
        Donnie Ewald
        [email protected]

        Comment

        Working...
        X