任何人都可以帮助如何替换包含空格,(, - ,等)等特殊字符的字符串。 让我们说我有一个字符串:
str=A Room Has (1 level) - (2 - leve) Rooms
Output string should be like:
str=A%Room%Has%%1%level%%%%2%%%leve%%Rooms
答案 0 :(得分:4)
这应该有效:
1
答案 1 :(得分:2)
试试这样:
@echo off
set "str=A Room Has (1 level) - (2 - leve) Rooms"
echo Before string substitution : %str%
pause
setlocal EnableDelayedExpansion
set "str=!str:-=%%!"
set "str=!str:(=%%!"
set "str=!str:)=%%!"
set "str=!str: =%%!"
Color 0A
echo After string substitution : !str!
pause