1.

Solve : Replace Spaces with Multiple Characters Batch Script?

Answer»

I am writing a Windows .BAT file which takes user input and creates a VARIABLE from their response. I need any SPACES within their response to be replaced with the characters %20 and then create a variable from the new string. How can I do this?

For example:
User is PROMPTED: What is your company name?
User answers: This is my company name
variable= This%20is%20my%20company%20name@echo off
setlocal enabledelayedexpansion
set string1=This Is My Company Name
set STRING2=!string1: =%%20!
echo string1 %string1%
echo string2 %string2%

output:

string1 This Is My Company Name
string2 This%20Is%20My%20Company%20Name

Works like a charm!
Thanks Salmon Trout!



Discussion

No Comment Found