Question About DeQuote Script

What is the colon doing in the following line after FINDSTR and before the GOTO command?

Echo.%DeQuote.Contents%|FindStr/brv ""^">NUL:&&Goto :EOF
^

I understand this part of the script is to act as a filter for vars without double quotes at beginning and end, but I don't understand the syntactical purpose of that colon. And never read about anything like it before. Otherwise I clearly see that the GOTO command is only meant to run if the FINDSTR command was successful, thus &&.

Also since regular expressions are being used, what is the ""^" actually searching for? Wouldn't the correct regexp be '^"' and '"$' to find double quotes at the beginning and end of variables? That way you would not need to use the /B and /E parameters either.

Re: Question About DeQuote Script

The DeQuote script is the result of a couple of newsgroup threads from back in 2001/2002. The original script (by frank) is discussed here The modified version is here

The colon you notice is a standard delimiter, you should (in theory at least) be able to use space/tab/colon/equals/semicolon interchangeably as command delimiters, I think a colon was chosen here to avoid line wraps in the newsgroup.

The reason the script is so complex is that it's designed to catch all possible cases of null values, quotes and spaces in the string, so that you can throw just about any string into the function and still get the desired output.

:: Sample variables: Set QuoteSpace="Quote And Spaces" Set QuoteNoSpace="QuoteNoSpaces" Set NoQuoteSpace=No Quote Spaces Set NoQuoteNoSpace=NoQuoteNoSpaces Set StartQuoteNoSpaceNoEndQuote="StartQuoteNoSpaceNoEndQuote Set NoStartQuoteNoSpaceEndQuote=NoStartQuoteNoSpaceEndQuote" Set StartQuoteSpaceNoEndQuote="Start Quote Spaces No End Quote Set NoStartQuoteSpaceEndQuote=No Start Quote Spaces End Quote" Set QuoteQuoteSpaceQuoteQuote=""Quote Quote Spaces Quote Quote"" Set QuoteQuoteNoSpaceQuoteQuote=""QuoteQuoteNoSpacesQuoteQuote"" Set TwoQuotesAndDelimiters=""Two Quotes;And,Delimiters=Fails"" ----This is the one case that fails

It should be noted this was written when NT4 was still very common - if you are running XP and 2003 you can probably just use %~1 to get a parameter without spaces. see http://ss64.com/nt/syntax-args.html I need to do some testing to see how the two methods compare with all the cases above.

Re: Question About DeQuote Script

Ahh hmm, no wonder. It was written in days of y'ore.

Well here is my own modification for modern days then, which as far as I see, should work in _EVERY_ instance. I typically prefer being able to pass multiple variables to small functions/scripts like this. Which is why it starts with a FOR loop.

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
:DeQuote
FOR %%G IN (%*) DO (
SET DeQuote.Variable=%%G
CALL SET DeQuote.Contents=%%!DeQuote.Variable!%%
IF [!DeQuote.Contents:~0^,1!]==[^"] (
IF [!DeQuote.Contents:~-1!]==[^"] (
SET DeQuote.Contents=!DeQuote.Contents:~1,-1!
) ELSE (GOTO :EOF no end quote)
) ELSE (GOTO :EOF no beginning quote)
SET !DeQuote.Variable!=!DeQuote.Contents!
SET DeQuote.Variable=
SET DeQuote.Contents=
)
GOTO :EOF

So it can be used as thus.SET VAR1="I am some text"SET VAR2=I am also some text"

CALL :DeQuote VAR1,VAR2

And only VAR1 will be dequoted. I still don't understand how the regexp search for ""^" is working in the original FINDSTR. Especially when it's searching for the double quote at the end.

Re: Question About DeQuote Script

I still don't understand how the regexp search for ""^" is working in the original FINDSTR. Especially when it's searching for the double quote at the end.

Searching for a quote with findstr is tricky because it already uses quote symbols to hold the search string

From memory FindStr/brv ""^" is combining the expression "" (which evaluates to a single quote) with the expression ^", which evaluates to nothing but simply stops findstr from complaining that the search string is missing a closing quote.

You might expect this should just be something like FindStr/brv """ or FindStr/erv """ but life is never that easy!!

The new version you've posted looks really promising, thanks for posting it, I'll have to have a play with it over the next day or two.

Re: Question About DeQuote Script

Simon Sheppard wrote:

Actually it just occurs to me it would be simple to add a SHIFT clause and have it dequote multiple variables passed as %1, %2 etc

Ahh yes, that would work equally well for passing multiple variables. I'm just a sucker for FOR loops . You should probably also add a note to that page that the function will require ENABLEDELAYEDEXPANSION.

Thanks for the lowdown on how that regexp is breaking down in the shell as well.

Re: Question About DeQuote Script

Thank you,

I actually figured it out about an hour after I posted my question and came up with the same results. This option works well because I can do character manipulation as well rather than just deleting the ones that are not needed.