我已经尝试使用此代码来验证文件的内容,我能够读取其中的内容。但是我应该读一下紧跟搜索单词.....
的单词例如在文本文件中,我有大约10行内容。
在第三行中找到了搜索到的单词,我应该阅读搜索到的单词的下一行。
考虑这是文本文件内容,
Hello
how
are
you
I am
fine
我需要搜索文本文件中是否存在单词“ how
”,如果找到了“ how
”,我应该阅读/验证该单词的下一行。 / p>
输出应为“ 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
”
答案 0 :(得分:0)
Here is the answer to your question
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