January 16, 2021, 05:23:46 AM

Author Topic: [bb] Parsing Strings by Oldefoxx [ 1+ years ago ]  (Read 412 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] Parsing Strings by Oldefoxx [ 1+ years ago ]
« on: June 29, 2017, 12:28:41 AM »
Title : Parsing Strings
Author : Oldefoxx
Posted : 1+ years ago

Description : 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.


Code :
Code: BlitzBasic
  1. Graphics 640,480
  2. ClsColor 0,0,128
  3. Cls
  4. example$="Now is the time for all good men to come to the aid of their party."
  5. Print example$
  6. a=parsecount(example$," ",0)
  7. Print a+" separate parsed elements found in example$"
  8. Print
  9. For b=1 To a
  10.   Print "Element #"+b+" = "+parse$(example$," ",b,0)
  11. Next
  12. WaitKey
  13. End
  14.  
  15. Function parsecount(sstring$,tstring$,flag)
  16. ;  sstring$ -- source string to be parse counted
  17. ;  tstring$ -- target string containing parsing characters
  18. ;  flag     -  flag to identify how parsed characters are grouped
  19. ;              0 -- use as a group
  20. ;              1 -- use singularly (same as ANY in other BASICs
  21. ;              2 -- use in pairs
  22. ;              3 -- use as triplets (and so on for 4 or more)
  23. Local count=0
  24. Local a=0
  25. Local b, c, d
  26. If tstring$>"" Then
  27.   Repeat
  28.     count=count+1
  29.     If flag>0 Then
  30.       b=0
  31.       c=1
  32.       While c<=Len(tstring$)
  33.         d=Instr(sstring$,Mid(tstring$,c,flag),a+1)
  34.         If b=0 Or d And d<b Then b=d
  35.         c=c+flag
  36.       Wend
  37.     Else
  38.       b=Instr(sstring$,tstring$,a+1)
  39.     End If
  40.     a=b
  41.   Until b=0
  42. EndIf
  43. Return count
  44. End Function
  45.  
  46. Function parse$(sstring$,tstring$,offset,flag)
  47. ;  sstring$ -- source string to be searched
  48. ;  tstring$ -- target string with parsing character(s)
  49. ;  flag     -- determines how target string is to be applied:
  50. ;              0 -- all at once
  51. ;              1 -- individually (same as ANY in other BASICs)
  52. ;              2 -- in pairs
  53. ;              3 -- in triplets (and so on for 4 and more)
  54. Local count=0
  55. Local a=0
  56. Local b, c, d
  57. If tstring$="" Then Return sstring$
  58. Repeat
  59.   If flag>0 Then
  60.     b=0
  61.     c=1
  62.     While c<=Len(tstring$)
  63.       d=Instr(sstring$,Mid(tstring$,c,flag),a+1)
  64.       If b=0 Or d And d<b Then b=d
  65.       c=c+flag
  66.     Wend
  67.   Else
  68.     b=Instr(sstring$,tstring$,a+1)
  69.   End If
  70.   count=count+1
  71.   If count=offset Then
  72.     If b=0 Then
  73.       Return Mid$(sstring$,a+1,Len(sstring$)-a)
  74.     Else
  75.       Return Mid$(sstring$,a+1,b-a-1)
  76.     End If
  77.   End If
  78.   If b=0 Then Return ""
  79.   a=b
  80. Forever
  81. End Function


Comments :


Rambus(Posted 1+ years ago)

 It would apear the code was posted improperly :P


Rambus(Posted 1+ years ago)

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


electronin(Posted 1+ years ago)

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


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal