测试某文件中字符串的重复次数

十二 30th, 2009

测试某文件中字符串的重复次数,写了很长时间了。经常用到,发上来备用。
可获得某文件中某字符串中某字符串出现的次数~

staTme=timer()
set fso=createobject("scripting.filesystemobject")
set t=fso.opentextfile(fso.getabsolutepathname("in.txt"),1)
set o=fso.opentextfile(fso.getabsolutepathname("out.xls"),2)
a=";"
do while not t.atendofstream
	p=t.readline
	if instr(a,";"&p&":")=0 then
		a=a&p&":1;"
	else
		at=""
		for each c in split(a,";")
			if c<>"" then
				if instr(c,p&":")>0 then
					if instr(c,":")>0 then
						pt=split(c,":")
						at=at&pt(0)&":"&cint(pt(1))+1&";"
					end if
				else
					at=at&c&";"
				end if
			end if
		next
		a=at
	end if
loop
o.write replace(replace(a,";",vbCrlf),":","	")
msgbox "导入成功,用时"&(timer()-staTme)*1000&"毫秒。"
staTme=timer()
set fso=createobject("scripting.filesystemobject")
set t=fso.opentextfile(fso.getabsolutepathname("in.txt"),1)
set o=fso.opentextfile(fso.getabsolutepathname("out.xls"),2)
a=";"
x=t.readall
for	each p in split(x,vbCrlf)
	if instr(a,";"&p&":")=0 then
		a=a&p&":1;"
	else
		at=""
		for each c in split(a,";")
			if c<>"" then
				if instr(c,p&":")>0 then
					if instr(c,":")>0 then
						pt=split(c,":")
						at=at&pt(0)&":"&cint(pt(1))+1&";"
					end if
				else
					at=at&c&";"
				end if
			end if
		next
		a=at
	end if
next
o.write replace(replace(a,";",vbCrlf),":","	")
msgbox "导入成功,用时"&(timer()-staTme)*1000&"毫秒。"
目前还没有任何评论.