从输入文件(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()
但是在输出文件中没有出现任何内容。有帮助吗?我希望此输出为例如
20/05/2013 22/05/2013 21.00.00.00 0000000054
答案 0 :(得分:1)
该行
* BEGIN DATE : 31/07/13
与条件
不匹配If (Left(strLine, 13) = "BEGIN DATE:")
你也需要ac * 计算 *作为“*”前缀。
拼出来:
>> 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