To remove double quotes just from the beginning and end of the String, we can use a more specific regular expression: String result = input. replaceAll("^\"|\"$", ""); After executing this example, occurrences of double quotes at the beginning or at end of the String will be replaced by empty strings.
A simple and elegant answer from Stripping single and double quotes in a string using bash / standard Linux commands only: BAR=$(eval echo $BAR) strips quotes from BAR . If you don't want anything printed out, you can pipe the evals to /dev/null 2>&1 .
The rule is simple: if it is not only one word, single-quote it. If you want variable expansion, always double-quote it.
%* expands to the complete list of arguments passed to the script. You typically use it when you want to call some other program or script and pass the same arguments that were passed to your script.
echo %myvar:"=%
This is not a limitation of the environment variable, but rather the command shell.
Enclose the entire assignment in quotes:
set "myvar=http://example.com?foo=1&bar="
Though if you try to echo this, it will complain as the shell will see a break in there.
You can echo it by enclosing the var name in quotes:
echo "%myvar%"
Or better, just use the set command to view the contents:
set myvar
While there are several good answers already, another way to remove quotes is to use a simple subroutine:
:unquote
set %1=%~2
goto :EOF
Here's a complete usage example:
@echo off
setlocal ENABLEDELAYEDEXPANSION ENABLEEXTENSIONS
set words="Two words"
call :unquote words %words%
echo %words%
set quoted="Now is the time"
call :unquote unquoted %quoted%
echo %unquoted%
set word=NoQuoteTest
call :unquote word %word%
echo %word%
goto :EOF
:unquote
set %1=%~2
goto :EOF
This works
for %a in (%myvar%) do set myvar=%~a
I would also use this if I wanted to print a variable that contained and ampersand without the quotes.
for %a in ("fish & chips") do echo %~a
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With