Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 批量查找和替换字符串中的字符_Batch File_Search_Replace_Scripting - Fatal编程技术网

Batch file 批量查找和替换字符串中的字符

Batch file 批量查找和替换字符串中的字符,batch-file,search,replace,scripting,Batch File,Search,Replace,Scripting,我有两个字符串变量: @echo关闭 设置字符串_1=abc def ghj 设置字符串_2=abc_def_ghj 在string_1中,我需要将空格替换为%20,因此结果将是: abc%20def%20ghj abc def ghj 在string_2中,我需要将\u替换为空格,因此结果将是: abc%20def%20ghj abc def ghj 我需要使用批处理(.bat)文件,有哪些选项可以执行此操作?您可以使用替换所需的字符 @echo off setlocal enabl

我有两个字符串变量:

@echo关闭
设置字符串_1=abc def ghj
设置字符串_2=abc_def_ghj
string_1
中,我需要将空格替换为
%20
,因此结果将是:

abc%20def%20ghj
abc def ghj
string_2
中,我需要将
\u
替换为空格,因此结果将是:

abc%20def%20ghj
abc def ghj
我需要使用批处理(.bat)文件,有哪些选项可以执行此操作?

您可以使用替换所需的字符

@echo off
setlocal enabledelayedexpansion

set "string_1=abc def ghj"
set string_2=abc_def_ghj

set new_string_1=!string_1: =%%20!
set new_string_2=%string_2:_= %

echo Old String 1: %string_1%
echo New String 1: %new_string_1%
echo Old String 2: %string_2%
echo New String 2: %new_string_2%
pause
我必须在字符串1中启用延迟扩展,以便内部和外部百分比符号不会相互抵消。

您可以使用替换所需的字符

@echo off
setlocal enabledelayedexpansion

set "string_1=abc def ghj"
set string_2=abc_def_ghj

set new_string_1=!string_1: =%%20!
set new_string_2=%string_2:_= %

echo Old String 1: %string_1%
echo New String 1: %new_string_1%
echo Old String 2: %string_2%
echo New String 2: %new_string_2%
pause
我必须在字符串1中启用延迟扩展,以便内部和外部百分比符号不会相互抵消。

您可以使用替换所需的字符

@echo off
setlocal enabledelayedexpansion

set "string_1=abc def ghj"
set string_2=abc_def_ghj

set new_string_1=!string_1: =%%20!
set new_string_2=%string_2:_= %

echo Old String 1: %string_1%
echo New String 1: %new_string_1%
echo Old String 2: %string_2%
echo New String 2: %new_string_2%
pause
我必须在字符串1中启用延迟扩展,以便内部和外部百分比符号不会相互抵消。

您可以使用替换所需的字符

@echo off
setlocal enabledelayedexpansion

set "string_1=abc def ghj"
set string_2=abc_def_ghj

set new_string_1=!string_1: =%%20!
set new_string_2=%string_2:_= %

echo Old String 1: %string_1%
echo New String 1: %new_string_1%
echo Old String 2: %string_2%
echo New String 2: %new_string_2%
pause
我必须在字符串1中启用延迟扩展,以便内部和外部百分比符号不会相互抵消。

最小范围:

注意
ENDLOCAL&设置“string\u 1=%string\u 1%”
行(不要更改它)

输出:

==>30087503.bat
1abc%20def%20ghj
2abc def ghj
最小范围:

注意
ENDLOCAL&设置“string\u 1=%string\u 1%”
行(不要更改它)

输出:

==>30087503.bat
1abc%20def%20ghj
2abc def ghj
最小范围:

注意
ENDLOCAL&设置“string\u 1=%string\u 1%”
行(不要更改它)

输出:

==>30087503.bat
1abc%20def%20ghj
2abc def ghj
最小范围:

注意
ENDLOCAL&设置“string\u 1=%string\u 1%”
行(不要更改它)

输出:

==>30087503.bat
1abc%20def%20ghj
2abc def ghj