Question : Replace a space with percent 20 (%20) in a batch file

I'm writing a script to convert file paths to web links. One part of it is giving me trouble. I need to replace all instances of a space in the string with %20.

The attached code is what seems like should work but it doesn't. I'm escaping the percent sign with another percent sign but the output comes out like this:

Afilewithaspace0

Thanks for your help!
1:
2:
3:
SET str=A file with a space
SET str=%str: =%%20%
echo %str%

Answer : Replace a space with percent 20 (%20) in a batch file

VBScript is generally a much better tool for text manipulation, as it has more versatile and won't choke on special characters.

That said, you can do it in batch like this:

1:
2:
3:
4:
5:
6:
7:
@echo off
setlocal enabledelayedexpansion

set str=A file with a space
set replace=%%20
set str=%str: =!replace!%
echo %str%
Random Solutions  
 
programming4us programming4us