'=========================================================================== ' Subject: STRING PARSER Date: 04-20-00 (21:22) ' Author: Hermann Seegert Code: PB ' Origin: hermann.seegert@t-online.de Packet: PB.ABC '=========================================================================== $if 0 Detmold, Germany 19.4.2000 ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿Ü ³ Hi everyone! ³Û ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙÛ ßßßßßßßßßßßßßßßßß Well, in the last time I've produced some parsers, as some of you possibly know already ;). Here is one, which is parsing a string by a given delimiter. You can decide, if you want to have the re- sults in an array or not. Comments can be sent to: hermann.seegert@t-online.de Programmed in PowerBASIC, V. 3.2 $endif $lib all off defint a-z '---- Demo Code begins..... cls shared h$(),ar text$="My~name~is~Hermann~Seegert~and~I'm~living~in~Germany" ? "Original Text$ is: ";text$ abs_sign$="~" 'Delimiter call parseit(text$,abs_sign$) 'call procedure ' locate 2,20 : ? "Outside of procedure...." for x=1 to ar locate x+2,20 ? "Arrayelement "+ltrim$(str$(x))+" "; : write h$(x) next x print repeat$(11,"FINISH "); end '---- Demo Code ends..... ' '-------------- splitting a string with one delimiter ------------- ' sub parseit(text$,abs_sign$) redim h$(100) 'isn't realy necessary, 'BUT possible ! option base 1 abs_l=len(abs_sign$) for a=1 to tally(text$,abs_sign$)+1 incr ar if a=1 then 'first part.... firstpart$=left$(text$,instr(text$,abs_sign$)-1) h$(ar)=firstpart$ write h$(ar) iterate end if 'The following may be isn't that easy, if you are a programing- 'beginner; find out, what I've done there! where_sign=instr(where_sign+abs_l,text$,abs_sign$) where2_sign=instr(where_sign+abs_l,text$,abs_sign$) if where2_sign=0 then 'last part...... lastpart$=mid$(text$,where_sign+abs_l) h$(ar)=lastpart$ write h$(ar) exit for end if centerpart_s$=mid$(text$,where_sign+abs_l,_ where2_sign-where_sign-abs_l) 'center part(s) h$(ar)=centerpart_s$ write h$(ar) next a end sub ' '****************************** EOF ********************************