使用DCL,我得到了一个3行的.txt文件
Line 1 test.
Line 2 test.
Line 3 test.我正在努力确保每一个都包含了预期的内容。我目前使用的是f@extract函数,它会给出第一行的输出,但我不知道如何验证第二行和第三行。我可以使用什么函数来确保第二行和第三行是正确的?
$ OPEN read_test test.dat
$ READ/END_OF_FILE=ender read_test cc
$ line1 = f$extract(0,15,cc)
$ if line1.nes."Line 1 test."
$ then
$ WRITE SYS$OUTPUT "FALSE"
$ endif
$ line2 = f$extract(??,??,cc) ! f$extract not possible for multiple lines?
$ if line2.nes."Line 2 test."
$ then
$ WRITE SYS$OUTPUT "FALSE"
$ endif发布于 2013-02-08 21:46:32
对于恰好3行,你可能只想做3次读取和3次比较...
$ READ READ/END_OF_FILE=ender read_test cc
$ if f$extract(0,15,cc).nes."Line 1 test." ...
$ READ READ/END_OF_FILE=ender read_test cc
$ if f$extract(0,15,cc).nes."Line 2 test." ...
$ READ READ/END_OF_FILE=ender read_test cc
$ if f$extract(0,15,cc).nes."Line 3 test." ...再多一些,你就会想要在回复时处于循环中。为了跟进Chris的方法,您可能希望首先准备一个值数组,然后循环读取和比较只要有值。未经测试:
$ line_1 = "Line 1 test."
$ line_2 = "Line 2 test."
$ line_3 = "Line 3 test."
$ line_num = 1
$ReadNext:
$ READ/END_OF_FILE=ender read_test cc
$ if line_'line_num'.nes.cc then WRITE SYS$OUTPUT "Line ", line_num, " FALSE"
$ line_num = line_num + 1
$ if f$type(line_'line_num').NES."" then GOTO ReadNext
$ WRITE SYS$OUTPUT "All provided lines checked out TRUE"
$ GOTO end
$Ender:
$ WRITE SYS$OUTPUT "Ran out of lines too soon. FALSE"
$end:
$ close Read_Test哈哈,海因。
发布于 2013-02-08 20:29:45
尝试这个变体(未经测试,因此可能需要进行一些调试)。使用符号替换来跟踪您要访问的行。
$ OPEN read_test test.dat
$ line_num = 1
$ ReadNext:
$ READ/END_OF_FILE=ender read_test cc
$ line'line_num' = f$extract(0,15,cc)
$ if line'line_num'.nes."Line ''line_num' test."
$ then
$ WRITE SYS$OUTPUT "FALSE"
$ endif
$ goto ReadNext
$ !
$ Ender:
$ close Read_Test
$ write sys$output "line1: "+line1
$ write sys$output "line2: "+line2
$ write sys$output "line3: "+line3
$ exithttps://stackoverflow.com/questions/14760592
复制相似问题