0

从输入文件(input.txt)开始,我必须找到一些字符串并将它们写入另一个文件txt(output.txt)这是input.txt

**********************************************************
* NAME           : CONTROLLER                                                          
* FUNCTION       : NOTHING IMPORTANT                                           
* BEGIN DATE     : 31/07/13                               
* TIME BEGIN     : 23.39.17.75                            
**********************************************************
* DATA INPUT READ  : 000000540                            
**********************************************************

这是代码:

Const ForReading = 1
Const ForWriting = 2
Dim objFSO 'File System Object
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objInputTS 'Text Stream Object
Set objInputTS = objFSO.OpenTextFile("D:\input.txt", ForReading, False)
Dim objOutputTS 'Text Stream Object
Set objOutputTS = objFSO.OpenTextFile("D:\output.txt", ForWriting, True)

Do Until objInputTS.AtEndOfStream
    Dim strLine
    strLine = objInputTS.ReadLine()
    If (Left(strLine, 13) = "BEGIN DATE:") Then objOutputTS.WriteLine(Mid(strLine, 20))
    If (Left(strLine, 13) = "TIME BEGIN:") Then objOutputTS.WriteLine(Mid(strLine, 20))
    If (Left(strLine, 18) = "DATA INPUT READ:") Then objOutputTS.WriteLine(Mid(strLine, 22))    
Loop

objOutputTS.Close()
objInputTS.Close()

但是在输出文件中什么也没有出现。有什么帮助吗?我想要这个输出用于 esxample

20/05/2013 22/05/2013 21.00.00.00 0000000054

4

1 回答 1

1

线

* BEGIN DATE     : 31/07/13

不符合条件

If (Left(strLine, 13) = "BEGIN DATE:")

您也必须为“*”前缀计算* 。

拼写出来:

>> s1 = "* BEGIN DATE     : 31/07/13"
>> s2 = Left(s, 13)
>> WScript.Echo """" & s2 & """"
>>
"* BEGIN DATE "
>> c1 = "BEGIN DATE:"
>> c2 = "* BEGIN DATE "
>> WScript.Echo 1, CStr(c1 = s2)
>> WScript.Echo 2, CStr(c2 = s2)
>>
1 False
2 True
于 2013-09-23T16:04:49.577 回答