January 26, 2021, 12:18:43 PM

Author Topic: [bb] VB Split Command by Chroma [ 1+ years ago ]  (Read 416 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] VB Split Command by Chroma [ 1+ years ago ]
« on: June 29, 2017, 12:28:42 AM »
Title : VB Split Command
Author : Chroma
Posted : 1+ years ago

Description : This command takes a string$ and splits it at the spaces and stores the individual words in the word$() array.  The global "max_word" stores the number of words.  I've got some good use out of this and I'm porting some other VB commands as well.  I'll post them here when finished.

Code :
Code: BlitzBasic
  1. ;Visual Basic Split Command
  2. ;by Chroma
  3.  
  4.  
  5. ;Set up variables
  6. ;These need to go in your program
  7. Dim word$(1)
  8. Global max_word=0
  9.  
  10.  
  11. ;Here's the test string
  12. test$="Blitz3D is the fastest 2d/3d gaming language!"
  13.  
  14. ;Split string at spaces
  15. Split(test$)
  16.  
  17. ;Print split string
  18. For i = 1 To max_word
  19.         Print word$(i)
  20. Next
  21.  
  22. ;Pause
  23. WaitKey
  24.  
  25. ;End the Program
  26. End
  27.  
  28.  
  29. ;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  30. ;Split Function a la Visual Basic
  31. ;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  32. Function Split(mystring$)
  33.  
  34. count=Len(mystring$)+1
  35. Dim word$(count)
  36. max_word=0 : start=1
  37.  
  38. For t=1 To count
  39.         If Mid(mystring$,t,1)=" " Or Mid(mystring$,t,1)=""
  40.                 max_word=max_word+1
  41.                 word$(max_word)=Mid(mystring$,start,t-start)
  42.                 start=t+1
  43.         EndIf
  44. Next
  45. End Function
  46. ;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal