TGC Codebase Backup



String Split by Vir Ex Machina

23rd Jan 2005 21:01
Summary

Splits a string around a split sequence



Description

Splits a string into tokens given a split token

ex: split(string,",")
print array count StrTable()

StrTable() is accessible in the global symbol table (?!?). I don't have a clue why. You can not pass arrays back and forth between functions it seems.



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    FUNCTION Split(inp as string, split as string)
   dim StrTable() as string
   empty array StrTable()

  s as string
  i as integer

  i = 1
  index = 1
  while index <= len(inp)
     s = ""
     for i = index to len(inp)
       if mid$(inp,i) = split then exit
       ` change this if you want quotes to
       ` s = s + mid$(inp,i)
       if mid$(inp,i) <> chr$(34) then s= s + mid$(inp,i)
     next i
     index = i + len(split) + 1

     Add To Queue StrTable()
     StrTable() = s
  Endwhile

ENDFUNCTION StrTable