Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/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
Windows 在批处理变量中存储多行字符串_Windows_Batch File - Fatal编程技术网

Windows 在批处理变量中存储多行字符串

Windows 在批处理变量中存储多行字符串,windows,batch-file,Windows,Batch File,我需要删除文件中可能出现的字符串。这个字符串有许多行我可以使用批处理脚本执行此操作吗? 我听说批量中不能有多行变量?字符串将来自另一个文件,我将使用批处理将该文件读入变量 以下代码似乎只在字符串中存储文件的第一行/最后一行??出什么事了 Rem Read file and store all contents in string Set replace= Set target= Set OUTFILE=res.txt for /f "delims=" %%i in (myFile.txt) do

我需要删除文件中可能出现的字符串。这个字符串有许多行我可以使用批处理脚本执行此操作吗?

我听说批量中不能有多行变量?字符串将来自另一个文件,我将使用批处理将该文件读入变量

以下代码似乎只在字符串中存储文件的第一行/最后一行??出什么事了

Rem Read file and store all contents in string
Set replace=
Set target=
Set OUTFILE=res.txt
for /f "delims=" %%i in (myFile.txt) do set target=%target% %%i

echo %target%
Rem When I print target I only have one line not many lines?? Whats going wrong

Rem Remove the target string from myOtherFile.txt: this code is from http://stackoverflow.com/questions/5273937/how-to-replace-substrings-in-windows-batch-file
for /f "tokens=1,* delims=¶" %%A in ( '"type myOtherFile.txt"') do (
SET string=%%A
SET modified=!string:%target%=%replace%!

echo !modified! >> %OUTFILE%
)
试试这个:

@echo off &setlocal enabledelayedexpansion
for /f "delims=" %%i in (myFile.txt) do set "target=!target! %%i"
echo %target%
在代码块内,对于具有可变值的变量,始终需要
延迟扩展。

尝试以下操作:

@echo off &setlocal enabledelayedexpansion
for /f "delims=" %%i in (myFile.txt) do set "target=!target! %%i"
echo %target%

在代码块内,对于具有可变值的变量,始终需要
延迟扩展。

尝试此操作,最后更改为:

echo !target!

尝试此操作,最后更改为:

echo !target!

可以将助手批处理文件
findrepl.bat
与/v开关一起使用,并通过指定开始和结束术语从文件中删除文本块。可以将助手批处理文件
findrepl.bat
与/v开关一起使用,并通过指定开始和结束术语从文件中删除文本块。