Solved Can someone explain my wrongdoing?

Hidde663 / My first build
February 6, 2018 at 01:58:26
Specs: Windows 10 Pro 64bit, i5-6600K[delid]@4.800GHz/4.600GHz cache@1.39v | 2x4GB Crucial-DDR4-2133@14-14-14-28 1T 2800MHz@1.37v
im trying to remove surrounding quotes from this variable, yet im getting an error.
if i change set "check=%check:~1,-1%" to set check=test i also get an error.
can anyone explain me what i am doing wrong?
here is the code:

set check="graf ana login settings.txt"
if '%check:~0,1%'=='"' set "check=%check:~1,-1%"

result:

set was unexpected at this time.

i5-6600K[delid]@4.800GHz/4.600GHz cache@1.39v | 2x4GB Crucial-DDR4-2133@14-14-14-28 1T 2800MHz@1.37v
ASUS Z170K
Samsung 250GB SSD 850 EVO
MSI Armor RX 570 4GB@1380c/2087m BiosMod
VS450


See More: Can someone explain my wrongdoing?

Report •

#1
February 6, 2018 at 02:11:50
✔ Best Answer
Did you mean you want to get rid from surrounding quotes from this variable set check="graf ana login settings.txt" and you expect as result like this graf ana login settings.txt
Try like this instead :

@echo off
set check="graf ana login settings.txt"
echo Before = %check% 
for %%a in (%check%) do ( set check=%%~a )
echo(
echo After = %check%
pause & exit


Report •

#2
February 6, 2018 at 02:28:27
thanks, it worked.

but i still do not understand how this is wrong: if '%check:~0,1%'=='"'
anything i do after the if statement is considered wrong

omg, now it does this, without error:

set check="graf ana login settings.txt"
if '%check:~0,1%"=='"' set "check=%check:~1,-1%"
echo %check%

result:

"graf ana login settings.txt"

but when i do this:

set check="graf ana login settings.txt"
if '%check:~0,1%"=='"' set "check=%check:~1,-1%"
echo %check%
set "check=%check:~1,-1%"
echo %check%

result:

graf ana login settings.txt

Something here must be wrong, but i dont see it

i5-6600K[delid]@4.800GHz/4.600GHz cache@1.39v | 2x4GB Crucial-DDR4-2133@14-14-14-28 1T 2800MHz@1.37v
ASUS Z170K
Samsung 250GB SSD 850 EVO
MSI Armor RX 570 4GB@1380c/2087m BiosMod
VS450

message edited by hidde663


Report •

#3
February 6, 2018 at 02:31:29
i guess it cant handle this: if '%check:~0,1%"=='"'

i5-6600K[delid]@4.800GHz/4.600GHz cache@1.39v | 2x4GB Crucial-DDR4-2133@14-14-14-28 1T 2800MHz@1.37v
ASUS Z170K
Samsung 250GB SSD 850 EVO
MSI Armor RX 570 4GB@1380c/2087m BiosMod
VS450


Report •

Related Solutions

#4
February 6, 2018 at 08:16:40
Specifically, it's the mismatched single/double quotes

How To Ask Questions The Smart Way


Report •

#5
February 6, 2018 at 08:23:12
i see now, thanks

but did not work, had to change it to this:

if '%1'=='' (notepad) else set "check=%1"
if '%check:~0,1%'=='%check:~-1%' set check=%check:~1,-1%

now i just check if 1 char is the same as last, which is not the best solution...

i5-6600K[delid]@4.800GHz/4.600GHz cache@1.39v | 2x4GB Crucial-DDR4-2133@14-14-14-28 1T 2800MHz@1.37v
ASUS Z170K
Samsung 250GB SSD 850 EVO
MSI Armor RX 570 4GB@1380c/2087m BiosMod
VS450

message edited by hidde663


Report •

#6
February 6, 2018 at 09:41:50
Correct. The best solution would be to use what Hackoo suggested. It's what I've always used, it's as clean as batch gets, and because you're not fighting CMD's double quote handling, it tends to cause the least number of problems. (Although Hackoo's exact code does technically add an extra space at the end of %check%.)

How To Ask Questions The Smart Way

message edited by Razor2.3


Report •

#7
August 29, 2018 at 02:44:39
Found another workaround, hackoo's solution is way better tho

@echo off
set check="graf ana login settings.txt"
echo Before = %check%
if %check:~0,1%"=="" set "check=%check:~1,-1%"
echo After = %check%

output=

Before = "graf ana login settings.txt"
After = graf ana login settings.txt

:)

i5-6600K[delid]@4.8GHz/4.3GHz@1.4v LLC=6 | 2x4GB Crucial-DDR4-2133CL15@14-14-14-28 1T 2700MHz@1.35v
MSI Armor RX 570 4GB@1340Mhz core@1.110v/1865MHz BiosModded


Report •

#8
August 29, 2018 at 05:55:05
IF statement breaks if first character is not a double quote.

How To Ask Questions The Smart Way


Report •

#9
August 29, 2018 at 06:01:49
triple quote too, but in this case im checking if nothing==nothing ;
if ""=="" echo :^)

:)

i5-6600K[delid]@4.8GHz/4.3GHz@1.4v LLC=6 | 2x4GB Crucial-DDR4-2133CL15@14-14-14-28 1T 2700MHz@1.35v
MSI Armor RX 570 4GB@1340Mhz core@1.110v/1865MHz BiosModded


Report •

Ask Question