### Author Topic: Command Line Seperator function  (Read 1658 times)

#### SBlectric

• Mc. Print
• Posts: 49
• Coding is neat I guess
##### Command Line Seperator function
« on: 2011-Dec-27 »
My first post! Woo!

When I call GETCOMMANDLINE\$() the commands are separated by either quotes (if they contain spaces) or just by spaces. Here is a function that will separate each one into elements of an array.

Check it out.

Code: (glbasic) [Select]
`FUNCTION CmdLine: cmd\$,e\$[]LOCAL a%,b%,exit%,pos%,endpos%cmd\$=REPLACE\$(cmd\$,CHR\$(92),"/")DIM e\$[0]WHILE 1IF pos>LEN(cmd\$)-1 THEN BREAKSELECT ASC(MID\$(cmd\$,pos,1))CASE 34 // if the value is an open quoteb=INSTR(cmd\$,CHR\$(34),pos+1) IF b<pos+1 endpos=-1 exit=1 ELSE endpos=b-1-(pos) ENDIFDIMPUSH e\$[],MID\$(cmd\$,pos+1,endpos)pos=b+1CASE 32 // if it's a spaceINC pos,1DEFAULT // if it's any other characterb=INSTR(cmd\$,CHR\$(32),pos) IF b<pos+1 endpos=-1 exit=1 ELSE endpos=b-1-(pos-1) ENDIFDIMPUSH e\$[],MID\$(cmd\$,pos,endpos)pos=bENDSELECTIF exit THEN BREAKWENDENDFUNCTION`
Cool stuff and whatever

#### Kitty Hello

• code monkey
• Prof. Inline
• Posts: 10739
• here on my island the sea says 'hello'
##### Re: Command Line Seperator function
« Reply #1 on: 2011-Dec-27 »
I think a solution already existed?
http://www.glbasic.com/forum/index.php?topic=2066.msg15078#msg15078

and.. hello, welcome to the forums.

#### SBlectric

• Mc. Print
• Posts: 49
• Coding is neat I guess
##### Re: Command Line Seperator function
« Reply #2 on: 2011-Dec-27 »
Oh. Sorry, didn't see that. Cool!
Cool stuff and whatever