BlitzCoder Essentials
•
Home Page
•
About BlitzCoder
•
Contributors
•
Terms of Use
•
Email Us
Main Areas
•
BlitzCoder Chat
•
Discussions
•
Articles/Tutorials
•
Code Database
•
Link Database
•
Showcase Area
•
Worklogs
•
Competitions
Special Areas
•
Undocumented
Other Blitz Sites
•
Blitz Basic Home
•
Blitz Showcase
•
BlitzPlay Library
Forum Login
Username:
Password:
•
Register Now!
BlitzCoder Code Archives Page
Main Codes Page
"Parse"
, by poedboy
Let's you parse strings with a chosen delimiter(defaults to comma(,)). Allows multiple strings to be parsed at the same time.
Code
;**************************************** ;Name: Parse.bb ;Author: A Pissed Off Boy ;Date: 9:09pm 12/28/03 ;Updated: n/a ;**************************************** ;Purpose: Let's you parse strings with a chosen delimiter(defaults to comma(,)) ; returns a null string when theres nothing left to parse ; I wanted the ability to parse multiple strings at the same time easily.. ; Hence its a little bloated but it works. Make sure you use FreeParser ; when necessary - else this might turn into a not so obvious memory leak! ;=========================================================================== ;DA TEST CODEZ ;=========================================================================== ;Example Code.... ;Txt$="the,cow,jumped,over,the,moon" ; ;TestParser%=CreateParser(Txt$,",") ; ;While Txt$<>"" ; Txt$=Parse$(TestParser%) ; Print Txt$ ;Wend ;FreeParser TestParser% ;WaitKey ;=========================================================================== ;TYPES ;=========================================================================== Type Parser Field Txt$,Delimiter$ End Type ;=========================================================================== ;FUNCTIONS ;=========================================================================== Function CreateParser(Txt$,Delimiter$=",") Local p.Parser=New Parser p\Txt$=Txt$ : p\Delimiter$=Delimiter$ Return Handle(p.Parser) End Function Function SetParserTxt(Parser%,Txt$) Local b.Parser=Object.Parser(Parser%) b\Txt$=Txt$ End Function Function Parse$(Parser%) Local b.Parser=Object.Parser(Parser%) Local Char%,Length%=Len(b\Txt$) If Length%<1 Then Return For Char%=1 To Length% If Mid$(b\Txt$,Char%,1)=b\Delimiter$ Output$=Left$(b\Txt$,Char%-1) b\Txt$=Right(b\Txt$,Len(b\Txt$)-(Len(Output$)+1)) Return Output$ EndIf Next Output$=Left$(b\Txt$,Char%-1) b\Txt$=Right(b\Txt$,Len(b\Txt$)-(Len(Output$)+1)) Return Output$ End Function Function FreeParser(Parser%) Delete Object.Parser(Parser%) End Function
Copyright(c) 2000-2004, BlitzCoder. All Rights Reserved.
Code software created by Krylar's Kreations