Function RegEx(strLine)
Set re = New RegExp
re.Pattern = "\s+"
re.Global = True
RegEx = Trim(re.Replace(strLine," "))
End Function
解决方案:
Set fso = CreateObject("Scripting.FileSystemObject")
For f = 1 to 300
Set file = fso.OpenTextFile(f & ".txt")
m = 21 : Max = 0 'm=总列数,Max=输出最大行数
ReDim arIn(m-1) : ReDim arOut(m-1)
Do Until file.AtEndOfStream
strLine = RegEx(file.ReadLine)
If strLine <> "" Then
ReDim PreServe ar(m-1,n)
For i = 0 to m-1
arIn(i) = arIn(i) & "$" & Split(strLine)(i) & " "
ar(i,n) = arIn(i)
Next
n = n + 1
End If
Loop
For i = 0 to m-1
For j = CLng(n/2) to 0 step -1
ar1 = Split(ar(i,n-1),ar(i,j))
If UBound(ar1) > 1 Then
For k = 1 to UBound(ar1) - 1
a = UBound(Split(ar1(k))) - 1
b = UBound(Split(ar(i,j))) - 1
If a >= 0 Then
arOut(i) = arOut(i)&Mid(Split(ar1(k))(a),2)&" "
Else
arOut(i) = arOut(i)&Mid(Split(ar(i,j))(b),2)&" "
End If
Next
Exit For
End If
Next
If UBound(Split(arOut(i))) > Max Then Max = UBound(Split(arOut(i)))
Next
For i = 0 to Max - 1
For j = 0 to m-1
If UBound(Split(arOut(j))) >= i Then
strOut = strOut & Split(arOut(j))(i) & vbTab
Else strOut = strOut & vbTab
End If
Next
strOut = Left(strOut,Len(strOut)-1) & vbCrLf
Next
fso.OpenTextFile("z" & f & ".txt",2,True).Write strOut
strOut = "" : n = "0"
Next
CreateObject("Wscript.Shell")
Function RegEx(strLine)
Set re = New RegExp
re.Pattern = "\s+"
re.Global = True
RegEx = Trim(re.Replace(strLine," "))
End Function作者: loquat 时间: 2013-10-20 22:39
1.可否用不一个数组存下这些文件的路径,然后再从数组里面读取打开。
2.如果您的文件有规律的话,完全可以
For i = 1 To 1000
Set file = fso.OpenTextFile("S" & i & ".txt")
Next i作者: 思想之翼 时间: 2013-10-21 10:56