标题: [问题求助] 【已解决】VBS:代码中如何添加 删除重复数据 的语句 [打印本页]
作者: 思想之翼 时间: 2022-10-24 07:23 标题: 【已解决】VBS:代码中如何添加 删除重复数据 的语句
本帖最后由 思想之翼 于 2023-3-3 14:37 编辑
下列代码输出的数据,未删重。
现欲删除重复数据(重复数据仅保留一个),如何添加代码?- Set fso = CreateObject("Scripting.FileSystemObject")
- For f = 1 to 100
- For z = 1 to 100
-
- Set file = fso.OpenTextFile("e:\统计1\" & Right("00" & f, 3) & "\" & "1_" & Right("00" & z, 3) & ".txt")
- m = 4 : 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("e:\统计2\" & Right("00" & f, 3) & "\" & "特例_" & Right("00" & z, 3) & ".txt",2,True).Write strOut
-
- strOut = "" : n = "0"
- Next
- Next
- CreateObject("Wscript.Shell")
-
- Function RegEx(strLine)
- Set re = New RegExp
- re.Pattern = "\s+"
- re.Global = True
- RegEx = Trim(re.Replace(strLine," "))
- End Function
复制代码
欢迎光临 批处理之家 (http://bathome.net./) |
Powered by Discuz! 7.2 |