Pete's Windows, Office, VB & SQL Blog

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

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.

Advertisement

Written by fisherpeter

April 7, 2011 at 12:29 pm

Posted in Windos Command Line Batch

Tagged with

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.