Cry How To...

Remove quotes from a string

When writing command files it is not uncommon to need to pass in a quoted string, but how to remove those quotes? Fortunatly this is quite simple:

set MyString=%MyString:"=%

This is using simple string substitution to remove any quotes.

For example the following command file:

@echo off
set quoted="Some text"
echo quoted: %quoted%
set quoted=%quoted:"=%
echo unquoted: %quoted%

would produce the output:

quoted: "Some text"
unquoted: Some text


One thing to be aware of is that the trick of using a substitution (used here) will remove every quote from a string, not just opening and closing quotes.

These notes have been tested with Windows 7 and may also apply to other versions of Windows.

About the author: is a dedicated software developer and webmaster. For his day job he develops websites and desktop applications as well as providing IT services. He moonlights as a technical author and consultant.