Page 1 of 1

A Critique on "Trim Quotes - Remove surrounding quotes"

Posted: 05 Apr 2011 09:47
by ghostmachine4
Source : Trim Quotes


It says
The FOR command can be used to safely remove quotes surrounding a string

The demonstration is supposed to remove double quotes surrounding a string. If that's the case, a simple remove might do, such as the method demonstrated here.

What if I feel that things are not so simple? For example, the batch code fails when there are strings such as

Code: Select all

@echo off
set str=test "cmd politic" test2
echo.%str%
for /f "useback tokens=*" %%a in ('%str%') do set str=%%~a
echo.%str%


So its supposed to remove the double quotes surrounding "cmd politic", but what i see is this

Code: Select all

C:\work>test.bat
test "cmd politic" test2
test "cmd politic" test2


when i should be getting

Code: Select all

test cmd politic test2


Again , a simple remove might be used for this case. Why a for loop? What does it mean by "safely remove double quotes surrounding a string"

DosItNotHelp

Re: A Critique on "Trim Quotes - Remove surrounding quotes"

Posted: 05 Apr 2011 22:33
by DosItHelp
"safely remove double quotes surrounding a string" was meant to mean surrounding the whole string, not counting double quotes within the string.
Any suggestions on how to formulate this better are welcome.