views:

957

answers:

2

I have the following string:

"C:\Program Files\Application\Path\executable.exe" -- "/flag"

I am trying to split the string so that I get:

array(0) = C:\Program Files\Application\Path\executable.exe

I don't care about the rest of the array since I am just concerned about the file path not the args.

+1  A: 

This will do it.

dim p : p = """C:\Program Files\Application\Path\executable.exe"" -- ""/flag"
dim r : r = mid(p,2,instr(2,p,"""")-2)
CptSkippy
You could also use `Left(p, InStr(p, """")-1)`.
Helen
@Helen, I chose mid because I had intended to jump the first quotation mark. My answer however did not take it into account, I've corrected it.
CptSkippy
both worked great! Thanks for the help. I was stuck in this for hours
A: 

If you don't want to mess with Mid and InStr, you can make use of regular expressions. For example, this will retrieve the first quoted substring (without the outer quotes) from your string:

Dim strCommandLine, strPath, re

strCommandLine = """C:\Program Files\Application\Path\executable.exe"" -- ""/flag"""

Set re = New RegExp
re.Pattern = """(.*?)"""

strPath = re.Execute(strCommandLine)(0).SubMatches(0)
Helen
both worked great! Thanks for the help. I was stuck in this for hours