aku1 发表于 2008-6-30 9:40:17 |
Const ForReading = 1 Const ForWriting = 2
Dim oFSO,oF,i,j,strline,strnewText,strnewText1 array1=array("111 bbb","222 aab","333 aaa","444 bbb","555 ccc","666 b") ScriptPath="C:\FSO"
Set oFSO = CreateObject("Scripting.FileSystemObject") Set oF = oFSO.CreateTextFile(ScriptPath & "file.txt") for i=0 to 5 oF.Writeline(array1(i)& vbCrLf) next
oF.close
' 包含 "b"。
Set objFile = oFSO.OpenTextFile(ScriptPath & "file.txt", ForReading)
Do Until objFile.AtEndOfStream strLine = objFile.ReadLine if instr(1,strline,"b",1)>0 then
strNewText = strnewtext&strLine & vbCrLF end if Loop
oF.close
Set objFile = oFSO.OpenTextFile("C:\FSo\file.txt", ForWriting)
objFile.WriteLine strNewText
objFile.Close
' 包含 "b"且两两显示
Set objFile = oFSO.OpenTextFile("C:\FSo\file.txt", ForReading)
Do Until objFile.AtEndOfStream strLine=objFile.ReadLine strline=replace(strline," ",",") strNewText1 = strnewtext1&strLine & "," loop MyArray=split(strNewText1,",",-1,1) oF.close
Set objFile = oFSO.OpenTextFile("C:\FSo\file1.txt", ForWriting)
For i = 1 to Ubound(myArray)/4
objFile.WriteLine myArray(4*i-3) &" " &myArray(4*i-1) Next
objFile.Close
|