Reputation: 55
I want to compare a single character with double quotes " in a in windows batch file.
@echo off
setlocal EnableDelayedExpansion
set var=before
for /f %%a in (zen.csv) do (
set var=%%a
echo !var:~-1!
IF "!var:~-1!"=="""" (
@echo found
)
)
pause
the result is like:
0
1
"
"
"
0
1
2
As you can see, the batch did not output the "found". How to compare a character with double quotes?
Upvotes: 4
Views: 1590
Reputation: 5372
@echo off
setlocal EnableDelayedExpansion
set var=before
for /f %%a in (zen.csv) do (
set var=%%a
echo !var:~-1!
IF !var:~-1!==^" (
@echo found
)
)
pause
Escape a double quote with a caret ^
to become ^"
. Omit the outer double quotes for the comparison. The caret will escape many characters except for %
which needs to be escaped by doubling up to become %%
.
Upvotes: 3