Code archives/Algorithms/Parsing Strings

This code has been declared by its author to be Public Domain code.

Download source code

Parsing Strings by Oldefoxx2001
PARSE$() and PARSECOUNT() are two functions that
provide a means to separate strings into component parts based on certain separation
characters, such as space, comma, parentheses or
brackets, etc.
Graphics 640,480
ClsColor 0,0,128
Cls
example$="Now is the time for all good men to come to the aid of their party."
Print example$
a=parsecount(example$," ",0)
Print a+" separate parsed elements found in example$"
Print
For b=1 To a
  Print "Element #"+b+" = "+parse$(example$," ",b,0)
Next
WaitKey
End

Function parsecount(sstring$,tstring$,flag)
;  sstring$ -- source string to be parse counted
;  tstring$ -- target string containing parsing characters
;  flag     -  flag to identify how parsed characters are grouped
;              0 -- use as a group
;              1 -- use singularly (same as ANY in other BASICs
;              2 -- use in pairs
;              3 -- use as triplets (and so on for 4 or more)
Local count=0
Local a=0
Local b, c, d
If tstring$>"" Then
  Repeat
    count=count+1
    If flag>0 Then
      b=0 
      c=1
      While c<=Len(tstring$)
        d=Instr(sstring$,Mid(tstring$,c,flag),a+1)
        If b=0 Or d And d0 Then
    b=0
    c=1
    While c<=Len(tstring$)
      d=Instr(sstring$,Mid(tstring$,c,flag),a+1)
      If b=0 Or d And d

Comments

Rambus2004
It would apear the code was posted improperly

:P


Rambus2004
didnt see the download .bb thing... Dont hit me


electronin2004
Yeah, some of the code seems to be missing :(


Code Archives Forum