任何人都能帮助如何替换包含空格、(、-、)等特殊字符的字符串吗。假设我有一个字符串:
str=A Room Has (1 level) - (2 - leve) Rooms
Output string should be like:
str=A%Room%Has%%1%level%%%%2%%%leve%%Rooms
这应该有效:
set "str=A Room Has (1 level) - (2 - leve) Rooms"
set "str=!str:-=%%!"
set "str=!str:(=%%!"
set "str=!str:)=%%!"
set "str=!str: =%%!"
这样尝试:
@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