Sign in to follow this  
Followers 0
rabbitkillrun2

Parsing arguments in a string

8 posts in this topic

#1 ·  Posted (edited)

I'm sure I'm not the first one to try this (everyone's tried making a command-line text-based program at some point, right?), but I couldn't find anything with the search, so I was wondering if anyone could help.

I've found tutorials such as these:

http://www.codeproject.com/KB/dotnet/TextQualifyingSplit.aspx

http://www.codeproject.com/KB/dotnet/TextParser.aspx

However, as I do not know C# or VB.NET, I'm having difficulty following them as I have to figure out what the code does as well as learn why it is doing what it does. I'm guessing (hoping) someone has already tried this in autoit and succeeded, so I'm wondering if I could get some basic help to start me off.

I'm making a basic rpg type game, and all input will be text based. So far, I've just been separating the input after the first space, so if they typed in "attack lunge" (not from game, just example), then that could be easily split. The problem comes when there is more than one argument.

Edited by rabbitkillrun2

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

AutoIt helpfile is the key to success, glory, fame, hapiness, ...

Using AutoIt >> Command line parameters will reveal you the Truth.

Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

Ah, yes, I know about them, but the thing is, I don't want parameters passed to the program. I'm using a GUI input box, so I need to parse them myself, with some sort of magic preferably.

Share this post


Link to post
Share on other sites

That's contradictory with both your title and the assesment made in the first post ("...making a command-line program...").

So your problem is parsing arguments in a string (that you get it from command-line or input box or TCP makes little difference).

Since the only version of AutoIt including "some sort of magic" is reserved for distribution to corporate alien companies, you'd have to rely on what the standard version can offer :mellow:

What are your grammar rules for parsing?


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

Sorry, it's been a busy day; my brain's not working at 100% of normal. I'll change it.

I will probably end up using doublequotes for each argument. I would love to have it comma separated, but to ignore commas within double quotes, as that'd be easier for the user when each argument is only a word or number, and not a sentence etc, but as long as it works in some way, I'll be happy with that for now.

I probably should have thoguht this out mroe before asking. I think I thought I'd just end up getting linked to some previous post that I'd missed, or some other tutorial on how to do it.

Thanks for the help. I'm off to lie down.

Share this post


Link to post
Share on other sites

For a simple grammar you can probably go with a state engine and a few regexp, but it all depends on how flexible / complex you intend the thing to be. Also don't forget that you might want to expand it much further in the future so don't choose a too simplistic approach you'd probably have to refactor fully in some time.

Get some rest, think twice and come ask again if you're stuck.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

I use this for parsing parameters in a string. It returns an array (or if nothing found, an @error):

$aParsedArray=StringRegExp($sStringToParse,'("[^"]*"|[^\s"]+)',3)

The PCRE can be altered to accommodate comma separated lists too, with this simple alteration:

$aParsedArray=StringRegExp($sStringToParse,'("[^"]*"|[^\s",]+)',3)

The array will include the quotations, so just use a StringReplace on the double-quotes for each entry.

*edit: Oops, I forgot the comma-separated lists might allow spaces. In that case take out the \s from the 2nd PCRE.

Edited by Ascend4nt

Share this post


Link to post
Share on other sites

Thanks, that's been a great help. :mellow:

Share this post


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
Sign in to follow this  
Followers 0