如何在文本文件中查找行 [英] How to find a line in a text file

查看:103
本文介绍了如何在文本文件中查找行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我当时在想,这就像是一个说话的模拟器,如果您写下批处理文件不知道的内容,它会要求您写出该问题的答案,然后再创建一个文本文件带有问题名称,并在文本文件中带有答案的一行.唯一的问题是我不知道如何使批处理文件读取文本文件中的行.请帮忙.

So i was thinking of this, this is supposed to be like a talking simulator, where if you write down something that the batch file does not know, it asks you to write the answer for that question, later creates a text file with the question name, and a line in the text file with the answer. The only problem is that i don't know how to make the batch file read the line inside of the text file. Please help.

@echo off
echo Hello!
echo Talk To Me!
pause>nul
:1
cls
echo Enter text
set /p talk=
if exist %talk% (
    goto answer
) else (
    goto dontknow
)
:answer
*finds string in txt file and writes it here*
pause>nul
goto 1
:dontknow
echo I dont know that yet. Teach me what to answer
set /p teach=
echo %teach% >> %talk%.txt
pause>nul
goto 1

推荐答案

读取.txt文件并将其显示为批处理文件.使用type命令.就您而言type %talk%

To read a .txt file and display it to a batch file. Use the type command. In your case type %talk%

在下面编辑(修改)了您的代码.

Have edited(minor) your code below.

   @echo off
echo Hello!
echo Talk To Me!
pause>nul
:1
cls
echo Enter text
set /p talk=
if exist %~dp0%talk%.txt (
    type %talk%.txt
     pause>nul
     goto 1
) else (
    goto dontknow
)

:dontknow
echo I dont know that yet. Teach me what to answer
set /p teach=
echo %teach% >> %talk%.txt
pause>nul
goto 1

这篇关于如何在文本文件中查找行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆