Replace space with %20

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
SteveT44
Posts: 3
Joined: 02 Dec 2009 08:52

Replace space with %20

#1 Post by SteveT44 » 02 Dec 2009 09:03

Hello,

Can anybody suggest a way to replace spaces in an environment variable with "%20"? The following:

set string=%string: =%%20%

removes the spaces and appends %20%.


Thanks

Steve T.

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

#2 Post by avery_larry » 02 Dec 2009 13:58

Code: Select all

@echo off
setlocal enabledelayedexpansion

set "string=string with a space"
set string=!string: =%%20!
echo %string%

SteveT44
Posts: 3
Joined: 02 Dec 2009 08:52

#3 Post by SteveT44 » 02 Dec 2009 14:29

Just what I needed!

Thanks


Steve

Post Reply