Reputation: 25
I'm trying to escape some characters in a string. The string is constantly changing, for example Set-Cookie: SESSION=60a8245bc1976b40d0d8c4ff6f9784fc; path=/
I want to remove Set-Cookie: SESSION=
and ; path=/
to leave 60a8245bc1976b40d0d8c4ff6f9784fc
.
But since it has "complex" characters, like :
=
/
returns an error when i try
SET cookies2=%cookies:Set-Cookie: SESSION=%
SET cookies3=%cookies2:; path=/=%
echo %cookies3%
Upvotes: 0
Views: 50
Reputation: 56180
use a for /f
loop to split the string:
@echo off
set "string=Set-Cookie: SESSION=60a8245bc1976b40d0d8c4ff6f9784fc; path=/"
set string
for /f "tokens=2 delims==;" %%a in ("%string%") do set "var=%%a"
echo -%var%-
Upvotes: 1