I have difficulties with following:
set myPath="program files"
echo.%myPath: =%20%
%%20 or ^%20 doesn't work too.
It seems impossible to replace something by percent character
Replace space in variable with %20
Moderator: DosItHelp
Hi,
I suppose you are right, it seems impossible to replace by percent this way.
But you can choose another way, an easy if you want to replace only spaces is ...
jeb
I suppose you are right, it seems impossible to replace by percent this way.
But you can choose another way, an easy if you want to replace only spaces is ...
Code: Select all
@echo off
setlocal enabledelayedexpansion
set myPath="program files are here"
call :replace %myPath%
echo %result%
goto :eof
:::::::::::::::::::::::::::::::
:replace
::: Only to remove the "
call :replace_int %~1
goto :eof
:::::::::::::::::::::::::::::::
:replace_int
setlocal
set tmp=
:replace.loop
set tmp=!tmp!%1
if "%2"=="" goto :finish
set tmp=!tmp!%%20
shift
goto :replace.loop
:finish
(
endlocal
set result=%tmp%
goto :eof
)
jeb
I played around and found the following working on my XP box:
----------------
----------------
Code: Select all
SETLOCAL ENABLEDELAYEDEXPANSION
set myPath=program files
echo."!myPath: =%%20!"
"program%20files"
----------------
Code: Select all
SETLOCAL ENABLEDELAYEDEXPANSION
set myPath="program files"
set myPath=!myPath: =%%20!
echo.%myPath%
"program%20files"
----------------
Code: Select all
SETLOCAL ENABLEDELAYEDEXPANSION
set myPath=program files
set myPath=!myPath: =%%20!
echo.%myPath%
program%20files
! !!!
Never heard of ! before?
and whats with the...
SETLOCAL ENABLEDELAYEDEXPANSION
and whats with the...
SETLOCAL ENABLEDELAYEDEXPANSION