Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.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
String 如何在.txt中搜索字符串?_String_Batch File_Search_Txtextcontrol - Fatal编程技术网

String 如何在.txt中搜索字符串?

String 如何在.txt中搜索字符串?,string,batch-file,search,txtextcontrol,String,Batch File,Search,Txtextcontrol,我想在.txt中搜索字符串 确定行后,需要在行的末尾添加另一个字符串 请帮忙 例如: ( echo 3-Trip-7000-23 echo 6-Lunch-600-2 echo 7-Breakfast-15-5 ) > FILE.txt 如果我键入午餐,它会在这种情况下打印午餐-600-2,因为在文件中搜索字符串午餐,我必须如何编码它。。。windows中的Im在顶部设置变量,我这样做是为了自动化反编译框架的rom构建 @echo off setlocal enableextensi

我想在.txt中搜索字符串

确定行后,需要在行的末尾添加另一个字符串

请帮忙

例如:

(
echo 3-Trip-7000-23 
echo 6-Lunch-600-2 
echo 7-Breakfast-15-5
) > FILE.txt

如果我键入午餐,它会在这种情况下打印午餐-600-2,因为在文件中搜索字符串午餐,我必须如何编码它。。。windows中的Im在顶部设置变量,我这样做是为了自动化反编译框架的rom构建

@echo off
setlocal enableextensions enabledelayedexpansion
set search=search for this string
set file=searchfile.txt
set addstring=add this string to the line

set count=0
for /F "usebackq tokens=*" %%A in ("%file%") do (
set /A count+=1
Echo.%%A | findstr /C:"%search%">nul && (set magicnumber=!count!)
)
set count=0
for /F "usebackq tokens=*" %%A in ("%file%") do (
set /A count+=1
if !count! == %magicnumber% echo %%A%addstring% >>tmp.txt
if !count! == %magicnumber% set line=%%A
if not !count! == %magicnumber% echo %%A >>tmp.txt
)
del /Q %file%
ren "tmp.txt" "%file%"
echo "%search%" is on line %magicnumber% and line has been changed to "%line%%addstring%"

我迷路了。您提到搜索字符串,然后切换到在文件末尾添加文本。请进一步解释,并尝试一下?我不明白为什么会将其标记为与txtextcontrol相关。