Page 1 of 1
Replace space in variable with %20
Posted: 17 Apr 2008 01:31
by honyk
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
Posted: 20 Apr 2008 15:57
by jeb
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 ...
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
Posted: 29 Apr 2008 00:42
by DosItHelp
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
! !!!
Posted: 30 Jun 2008 03:36
by Thebetr1
Never heard of ! before?
and whats with the...
SETLOCAL ENABLEDELAYEDEXPANSION