VB6 Collection实现百万文本去重

上一篇数组的去重说到,对于千次计算以上的去重基本上特别的吃力,这里就介绍一种方法,通过Collection集合对象来过滤重复。

Option Explicit

'//By: InkHin

'// 参考:https://bbs.csdn.net/topics/350065116

'引用:Microsoft scriptiong Runtime

'感谢 析弱大叔 qq: 1265382638  的指点.

'// 2019-03-10


'// 测试 Collection 去重 百万条文本数据过滤

'// 请编译执行

Private Function Out_Remove_Same(ByVal Path As String, ByVal InName As String, ByVal OutName As String)
Dim col As Collection
    Set col = New Collection
    Dim fso As Variant
    Set fso = CreateObject("Scripting.FileSystemObject")
    Dim stream1 As Scripting.TextStream
    
    'Function BuildPath(Path As String, Name As String) As String  '目录路径 文件名称
    
    Set stream1 = fso.OpenTextFile(fso.BuildPath(Path, InName), ForReading, False)
    
    Dim stream2 As Scripting.TextStream
    
    Set stream2 = fso.OpenTextFile(fso.BuildPath(Path, OutName), ForWriting, True)
    
    While Not stream1.AtEndOfStream
        Dim strLine As String
        strLine = stream1.ReadLine
        
        Dim vntValue As Variant
        vntValue = Empty
        
        On Error Resume Next
        vntValue = col.Item(strLine)
        On Error GoTo 0
        
        If IsEmpty(vntValue) Then
            Call col.Add(Null, strLine)
            Call stream2.WriteLine(strLine)
        End If
    Wend
    
    Call stream1.Close
    Call stream2.Close
End Function

 

转载于:https://www.cnblogs.com/lingqingxue/p/10506866.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值