windows - How to replace with percent character in cmd.exe? -


in windows command prompt, trying replace space in set string=hello world string %20. naively trying use string literal %20 this:

set string=%string: =%20% 

results in helloworld20%. trying use escape character ^ this:

set string=%string: =^%20% 

also results in helloworld20%. trying escape % doubling this:

set string=%string: =%%20% 

results in helloworld%20%. tried use variable replacement this:

set r=%20 set string=%string: =%r%% 

which results in helloworldr%%.

i found this, handles escaping of percent characters in variables. found this, handles escaped input of percent characters. neither 1 seems apply string replacing.

a tutorial/docu page windows cmd.exe found online tells me have correct syntax, not cover replacing percent characters.

after reading of those, tried:

setlocal enabledelayedexpansion set string=!string: =%20! 

which results in !string: =%20!.

i out of ideas, can help?

you need delayed expansion in case:

set "str1=hello world!" set "str2=%20" /f "delims=" %a in ('cmd /v:on /c @echo "%str1: =!str2!%"') set "str3=%~a" echo %str3% 

what delayed expansion?


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -