dim stem as string,snew as string open "c:\input.dat" for input as #1 do while not eof(1) line input #1,s s=s+vbcrlf if instr(1,snew,vbcrlf+s)=0 then snew=snew+s end if loop close #1 open "c:\output.dat" for output as #1 print #1,snew close #1估计快不了 -_-!!
刚才马虎了,上面代码有两处bug: 1、dim s as string写成dim stmp as string了 2、第一行和第二行若重复该代码去除不掉 不改了,呵呵
open "c:\input.dat" for input as #1
do while not eof(1)
line input #1,s
s=s+vbcrlf
if instr(1,snew,vbcrlf+s)=0 then
snew=snew+s
end if
loop
close #1
open "c:\output.dat" for output as #1
print #1,snew
close #1估计快不了 -_-!!
1、dim s as string写成dim stmp as string了
2、第一行和第二行若重复该代码去除不掉
不改了,呵呵
Const adLockOptimistic = 3
Const adCmdText = &H0001Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")strPathToTextFile = "C:\Scripts\"
strFile = "Test.txt"objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strPathtoTextFile & ";" & _
"Extended Properties=""text;HDR=NO;FMT=Delimited"""objRecordSet.Open "Select DISTINCT * FROM " & strFile, _
objConnection, adOpenStatic, adLockOptimistic, adCmdTextDo Until objRecordSet.EOF
Wscript.Echo objRecordSet.Fields.Item(0).Value
objRecordSet.MoveNext
Loop
*****************************************************************************
欢迎使用CSDN论坛阅读器 : CSDN Reader(附全部源代码)
http://www.cnblogs.com/feiyun0112/archive/2006/09/20/509783.html
--------------
可以试试用ACCESS与文本做个链接表,然后然后distinct
尤其是连接完整内容万万不可用snew=snew+s!!! 这是所有的行读文件的瓶颈!!!!
写文件也不要一行行的写。
而是都因该读到内存中,在写回去。
对于8W行的文本文件, 是占用不了多少内存的。
1: 完整的2进制读文件。
利用高效的split按照chrb(10) & chrb(13) 分割2: 快速排序, 关于排序中字符串的比较可调用 api: lstrcmp, 这个api大概可以提高3倍速度
还有个注意的! 快速排序的并不是要把字符串移置, 而是应该建立一个索引表,
只是对索引表排序。 有能提高2被速度。3: 便利索引表, 看想格两行是否相同, 如果是, 则写一行。
不出意外, 8W的记录排序写文件后, 应该在5秒不到的时间完成。
代码留给楼主自己写。
http://community.csdn.net/Expert/topic/4825/4825949.xml?temp=9.901065E-02问题在于字符串连接,我写了个CStringBuffer类,是模仿Java的StringBuffer
也许实现方法比较笨拙,但也许可以结决大字符串连接问题
http://blog.csdn.net/viena/archive/2005/10/10/498612.aspx
split是vb中效率最快的函数之1。
split是很耗资源的,它的结果是字符串数组,每个元素都是字符串
运算当然不会慢,慢在分配内存上