[quote=117006:@Alexander van der Linden]How do I get the second parameter in the system.commandline?
When I doubleclick on a associated (associated with my app) file the commandline is something like:
“c:\program files\myapp\myapp.exe” “c:\users\sander\database.db”
The quotes are in the string, so I thought I look for the literal pattern " " (double quote space double quote) to check wether there is a second parameter but how to search for quotes in Xojo?[/quote]
If Kem was around, he may have some magical Regex that does that in a pass, but here is my method which, as usual, has been tested.
A simple split will not do, because a typical argument call in Windows command line can be done with arguments without quotes, or with quotes for arguments containing spaces. Like so :
"C:\\Users\\Michel\\AppData\\Local\\Temp\\DebugMy Application\\DebugMy Application.exe" "firstarg" "secondarg" thirdarg "fourth arg"
Notice how thirdarg has no quotes, and “fourth arg” contains a space.
So the trick is to be able to distinguish between spaces between arguments, and spaces inside arguments. What I do is firt replace quote-space and space-quote by §, then single quotes by §, then finally do the split with §. I have used § because it is unusual, but any other character can do.
dim buf as string = replaceall(system.CommandLine,chr(34)+" ","§")
buf = replaceall(buf," "+chr(34),"§")
buf = replaceall(buf,chr(34),"§")
buf = replaceall(buf,"§§","§")
dim myarray(-1) as string
myarray = split(buf,"§")
for i as integer = 0 to myarray.Ubound-1
ListBox1.addrow(myarray(i))
next
At the end, each argument is entered in a different row of the ListBox. It’s up to you to adapt the method to your own needs