troubleshooting Question

Parse a .conf or similar file with different command line "switches" on each line.

Avatar of Johnjces
JohnjcesFlag for United States of America asked on
Delphi
52 Comments4 Solutions411 ViewsLast Modified:
I am a terrible parser! I have great difficulty and after many lines of redundant delete() and copy() and Pos() functions later I sort of have something sort of working but there must be a  cleaner/better simpler way.

I have a .conf or a .cfg file that I need to parse. Each line in this file is a command line. At a minimum the path and name of another file/executable is needed then various switches which can be in any order. EXxample;

C:\MyWork\MyExecutable.exe                                                { Minimum item required }
C:\Delphi\MyThingy.exe -a c:\readme.txt                               { -a switch then the item follows }
C:\Programs\Stuff\Program.exe -s normal -a c:\readme.txt   { Added -s switch which could be before or after the -a switch and item }

Of course other switches could be added as needed.

The first part of the line must be the executable then the switches (-a, -s, -q and etc.)  that tell me what follows and such can be in any order.

Can anyone point me in the right direction, component or code?

Thanks
ASKER CERTIFIED SOLUTION
MerijnB
Sr. Software Engineer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 4 Answers and 52 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 4 Answers and 52 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros