【问题标题】:Batch : Read only a Paragraph and Repeat for another paragraph from txt file批处理:从 txt 文件中读取一个段落并重复另一个段落
【发布时间】:2013-12-11 14:50:49
【问题描述】:

我正在尝试用批处理制作一个简单的问题游戏。像这样:

------- This is Ascii --------

1. This is First Question
   a. this is option a
   b. this is option b
   c. this is option c
   d. this is option d

Put Your Answer > [a/b/c/d]

而我想要的是:

我希望我的游戏从文本文件中加载问题,因为问题很多

这是我的 Question.txt 文件示例:

1. This is First Question
   a. This is option a
   b. This is option b
   c. This is option c
   d. This is option d

2. This is Second Question
   a. This is option a
   b. This is option b
   c. This is option c
   d. This is option d

3. This is Third Question
   a. This is option a
   b. This is option b
   c. This is option c
   d. This is option d

我正在尝试使用 FOR 命令等...我没有弄清楚主菜单和其他东西,我有自己的。我的问题仅此而已。 你能帮我弄清楚吗?

【问题讨论】:

    标签: file batch-file text windows-7 command-prompt


    【解决方案1】:

    这使用了一个名为 findrepl.bat 的辅助批处理文件,来自 - https://www.dropbox.com/s/rfdldmcb6vwi9xc/findrepl.bat

    findrepl.bat 放在与批处理文件相同的文件夹中或路径上。

    确保您的question.txt 在底部有一个空行,然后试试这个:

    @echo off
    for /L %%a in (1,1,3) do (
       echo.
       type "question.txt" | findrepl "^%%a. " /e:"^$"
       pause
    )
    

    这段代码的另一种使用方式是这样的

    type "question.txt" | findrepl "^1. " /e:"^$"
    pause
    type "question.txt" | findrepl "^2. " /e:"^$"
    pause
    type "question.txt" | findrepl "^3. " /e:"^$"
    pause
    type "question.txt" | findrepl "^4. " /e:"^$"
    pause
    

    【讨论】:

    • 你能告诉我如何使用 findrepl 吗?我的意思是我不明白 (| findrepl "^4. " /e:"^$" ) 是什么...谢谢你之前
    • 引号内的 ^ 表示将其作为行首。所以它在一行的开头搜索1. ,然后搜索结尾/e:,这是下一个没有字符的空行。 $ 表示行尾,因此 ^$ 表示使用行的开头和结尾,中间没有任何内容。这些被称为regular expressions。每个词与以不同数字开头的搜索词相同。
    猜你喜欢
    • 1970-01-01
    • 2021-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-11
    • 2020-11-17
    • 1970-01-01
    • 2015-03-30
    相关资源
    最近更新 更多