本帖最后由 apang 于 2013-3-4 11:07 编辑
- Set FSO = CreateObject("Scripting.FileSystemObject")
- Set File = FSO.OpenTextFile("a.txt")
- T = Time
- Do Until File.atEndOfStream
- Text = File.ReadLine
- If RegEx <> "" Then '排除空行
- A = Split(RegEx," ")
- m = UBound(A) 'm=列数
- ReDim PreServe B(m,n) '申明数组B
- For i = 0 to m :B(i,n) = A(i) :Next '数组B赋值
- n = n + 1 '行数
- End If
- Loop
-
- n = n - 1
- For i = 1 to m 'm=列数
- For j = 0 to n 'n=行数
- flag = 1
- For k = j + 1 to n
- If B(i,j) = B(i,k) Then '相等则赋值为上一行的值
- flag = 0 :B(i,j) = B(i,k-1) :Exit For
- End If
- Next
- If flag Then B(i,j) = " " '不相等则赋值为空格
- Next
- Next
-
- For i = 0 to n '写入文件
- Str = ""
- For j = 1 to m : Str = Str & vbTab & B(j,i) : Next
- FSO.OpenTextFile("b.txt",8,true).WriteLine B(0,i) & Str
- Next
- MsgBox T & vbLf & Time
-
- Function RegEx()
- Set Re = New RegExp
- Re.Pattern = "\s+"
- Re.Global = True
- RegEx = Trim(Re.Replace(Text," "))
- End Function
复制代码 保存为test.vbs,不知道能否满足要求,试一下 |