Pete's Windows, Office, VB & SQL Blog

Problems I have solved (or not) and good ideas I've found

Archive for April 7th, 2011

Removing Quotes from Quoted Strings in Windows batch (or .cmd)

leave a comment »

Passing strings between batch files or called routines means they inevitably have to be enclosed in double quote marks (e.g. “String to pass” ) if they are required in one variable.

Once the receiver gets hold of the string and tries to embed it in another string the quotes must be removed.

This simple approach comes from: http://ss64.com/nt/syntax-esc.html.

   :: Remove quotes
   SET _string=###%_string%###
   SET _string=%_string:"###=%
   SET _string=%_string:###"=%
   SET _string=%_string:###=%

The above will only work for non-null strings.  There is a link at the site for a more detailed solution.

Avoid using solutions involving %1 %2 %3 etc as they eliminate double spaces.

Written by fisherpeter

2011 April 7 at 12:29

Posted in Windos Command Line Batch

Tagged with

Follow

Get every new post delivered to your Inbox.