Jump to content

Help Parsing Spaces from cmdline parameters

Recommended Posts

I found the below code on the forum a while back when searching around. I have a script that uses the below code that when the compiled script runs with the /Name= switch is reads the part after the = in order to get the value and set the value as $var or in the below case $GetCMDLineValue. It works great if there is no spaces in the value specified. Normally I would put quotes around the value and off it goes but no matter how I format it I only gets the leftside of the first space. There may be a metter way of doing this but this is what I came up with so far based on what I read and found!

How can I make it so I can pass /Name="This is a Value" and have $GetCMDLineValue get set as "This is a Value"?

$GetCmdLine = $CmdLineRaw
$GetCmdLine1 = '/Name='
Global $GetCmdLineValue = StringMid($GetCmdLine, (StringInStr($GetCmdLine, $GetCmdLine1) + StringLen($GetCmdLine1) + 0), StringInStr($GetCmdLine, " ", 0, 1, StringInStr($GetCmdLine, $GetCmdLine1) + StringLen($GetCmdLine1)) - (StringInStr($GetCmdLine, $GetCmdLine1) + StringLen($GetCmdLine1)))

Thanks in advance,


Link to post
Share on other sites

You can use StringRegExp too :)

#include <Array.au3>
#include <StringCostants.au3>

Global $strString = '/CmdLine1=Value1 ' & _
                    '/CmdLine2=Value with spaces ' & _
                    '/CmdLine3="Value with double quotes"' & _
                    '/CmdLine4="C:\Users\SomeUser" /CmdLine5s=', _
       $strPattern = '(?:\/[^=]+=)([^\/]+)', _

$arrResult = StringRegExp($strString, $strPattern, $STR_REGEXPARRAYGLOBALMATCH)



(?:): non-capturing group. Everything is inside these group won't be "captured";
\/: Literally the character slash. It needs to be escaped, so the backslash character is used to escape it;
[^=]+: Everything that is not an equal symbol, with the quantifier 1 or more;
=: Literally the equal sign;
([^\/]+): capturing group. Everything that is not a slash, with the quantifier 1 or more.


Click here to see my signature:




Link to post
Share on other sites

You could just use $CmdLineRaw to get the whole, then divide that up yourself using StringSplit etc, if you know what to separate on.

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.


What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...