Removing double quotes from variables in batch file creates problems with CMD environment

前端 未结 11 587
春和景丽
春和景丽 2020-12-04 11:25

Can anybody help with effective and safe way of removing quotes from batch variables?

I have written a batch file which successfully imports a list of parameters %1,

11条回答
  •  醉酒成梦
    2020-12-04 11:58

    Spent a lot of time trying to do this in a simple way. After looking at FOR loop carefully, I realized I can do this with just one line of code:

    FOR /F "delims=" %%I IN (%Quoted%) DO SET Unquoted=%%I
    

    Example:

    @ECHO OFF
    SET Quoted="Test string"
    
    FOR /F "delims=" %%I IN (%Quoted%) DO SET Unquoted=%%I
    
    ECHO %Quoted%
    ECHO %Unquoted%
    

    Output:

    "Test string"
    Test string
    

提交回复
热议问题