[bb] VB Split Command by Chroma [ 1+ years ago ]

Started by BlitzBot, June 29, 2017, 00:28:42

Previous topic - Next topic

BlitzBot

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) Select
;Visual Basic Split Command
;by Chroma


;Set up variables
;These need to go in your program
Dim word$(1)
Global max_word=0


;Here's the test string
test$="Blitz3D is the fastest 2d/3d gaming language!"

;Split string at spaces
Split(test$)

;Print split string
For i = 1 To max_word
Print word$(i)
Next

;Pause
WaitKey

;End the Program
End


;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;Split Function a la Visual Basic
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Function Split(mystring$)

count=Len(mystring$)+1
Dim word$(count)
max_word=0 : start=1

For t=1 To count
If Mid(mystring$,t,1)=" " Or Mid(mystring$,t,1)=""
max_word=max_word+1
word$(max_word)=Mid(mystring$,start,t-start)
start=t+1
EndIf
Next
End Function
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


Comments : none...