Jump to content


 

- - - - -

_StringParseParameters

Parameters Parse Command Line

  • You cannot reply to this topic
No replies to this topic

#1 Ascend4nt

    Mass Spammer!

  • Full Members
  • PipPipPipPipPipPip
  • 1,029 posts
  • Gender:Male
  • Location:NJ

Posted 04 February 2009 - 06:34 PM

I forgot to update this, I had responded to a topic 'StringSplit $CmdLineRaw' with an updated PCRE for parsing individual items/options, so here's the updated code:

_StringParseParameters: Parse Parameters in a string: Returns an array as if a command-line parser split the elements, or if nothing found an @error.

Note there is a look-behind and look-ahead assertion to prevent grabbing quotes, while also allowing for cases where there are empty quotes (""):

[ autoIt ]    ( Popup )
Local $aParsedArray=StringRegExp($sStringToParse,'((?<=\s"|^")[^"]+(?=")|[^\s"]+)',3)

The only thing I'd do beforehand is expand any environment strings like %windir%. All you'd need for that is to just set the "ExpandEnvStrings" option, assign the string to itself (looks dumb, but accomplishes the needed expansion), then reset the option. (or call the ExpandEnvironmentStrings API function)


The old version of this can still be found in a post I had made in the thread 'Parsing arguments in a string' - it also parses comma-separated arguments, though retaining quotes. That could easily be remedied though.

Edited by Ascend4nt, 14 September 2011 - 03:50 AM.








1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users