BATCH_ Strip surrounding double quotes from string
Testing a batch string for surrounding quotes is quite annoying. Here is a solution for Windows 2000 and newer:
T keeps the string "Hello World!" with the surrounding quotes. The (simplified) test
:: %T% contains the test-string IF "%T:~0,1%%T:~0,1%" == """" IF "%T:~-1%%T:~-1%" == """" ( SET T=%T:~1,-1% )You can see, I am using the first respectively the last character twice, because a single double quote would break the IF. I'll explain it with this little example:
T keeps the string "Hello World!" with the surrounding quotes. The (simplified) test
IF %T:~0,1% == " (...)
would expand toIF " == " (...)
which will be parsed as IF <string>
with the string being " == " (...). Cannot work, huh?cypressor - 25. Nov, 21:06