0

我已经尝试过这段代码来验证文件的内容,并且我能够读取内容,但我应该读取与搜索单词直接相关的单词。

例如在文本文件中我有大约 10 行内容;在第三行我找到了搜索词,我应该阅读搜索词的下一行。考虑这是一个文本文件内容:

Hello
how 
are 
you 
I am 
fine

我需要搜索how文本文件中存在的how单词,如果找到该单词,我应该读取/验证该单词的下一行。

输出应该是are

open file "D:\Automation\EGGPlant\Archiecture\Script-Demo.suite\Resources\Demo.txt"

read from file "D:\Automation\EGGPlant\Archiecture\Script-Demo.suite\Resources\Demo.txt" 

put file  "D:\Automation\EGGPlant\Archiecture\Script-Demo.suite\Resources\Demo.txt"  into WiFiInfo

重复 WiFiInfo 的行数次:

put line repeatindex() of WiFiInfo into output

    if output contains "how" then
        Log "found"
    else 
        Log "Not found"
    end if

end repeat 

预期结果应该是are

4

1 回答 1

1

这是您问题的答案

Set dataFile to (file ResourcePath("Test.txt"))

set output to "how" // variable to set with the value "how

split dataFile by newline // all the values from the text file will be split and put into a list so that we can access it based on it position

repeat each item of dataFile
    if item repeatindex() of dataFile contains output then // statement check each item with the variable which is containing "how"
        log item repeatindex()+1 of dataFile // repeatindex()+1 will point the next index of current index
        exit repeat // Repeat will exit once the condition is true
    end if
end repeat
于 2019-07-25T11:19:46.747 回答