1.

Solve : Escape character for " in IF DOS command?

Answer»

I'm trying to CONDITIONALLY remove a possible leading " character in a variable. I thought this would work:

Code: [Select]IF '%TEMP:~0,1%' EQU '"' SET TEMP=%TEMP:~1%
but I GET the error message "SET was unexpected at this time.".

Thanks in advance for any help you may be able to provide.Try
Code: [Select]IF "%TEMP:~0,1%"=="^"" SET TEMP=%TEMP:~1%

This might be useful too:

Code: [Select]@echo off
set var="abc
set "var=%var:"=%"
echo.-%var%-
pause
And this if it is surrounded by quotes:

Code: [Select]for /f "delims=" %%a in ("%var%") do set "var=%%~a"Actually, if it is surrounded by quotes then you don't use the quotes in the () so this is more APPROPRIATE:

Code: [Select]for /f "delims=" %%a in (%var%) do set "var=%%~a"



Discussion

No Comment Found