本帖最后由 Nsqs 于 2016-12-27 09:00 编辑
- dim read(1),sc(1),m(1,1)
- set fso=CreateObject("Scripting.FileSystemObject")
- set regexp=new regexp
- file=array("a.txt","b.txt")
- with regexp
- .Global=-1:.IgnoreCase=-1
- .Pattern="(\d).*(\d).*(\d).*(\d)"
- for list=0 to ubound(file)
- read(list)=.Replace(fso.opentextfile(file(list)).readall,"$1$2$3$4") '格式化文本剔除其他字符包括空格和特殊字符在内
- sc(list)=split(read(list),vbcrlf)
- next
- .Pattern="((\d{2})\d{2})"
- for list1=0 to ubound(sc(0))
- m(0,0)=.replace(trim(sc(0)(list1)),"$2")
- m(0,1)=.Replace(sc(0)(list1),"$1")
- for list2=ubound(sc(1)) to 0 step -1
- if not .test(sc(0)(list1)) then exit for '文本行数不一或条件不符则忽略本次比较
- m(1,0)=.replace(trim(sc(1)(list2)),"$2")
- m(1,1)=.Replace(sc(1)(list2),"$1")
- if m(0,0)=m(1,0) then result=result&trim(m(1,1))&vbcrlf '满足条件提取b.txt数据
- next
- next
- .Pattern="(\d)(\d)(\d)(\d)":result=.Replace(result,"$1 $2 $3 $4")
- .Pattern="^(.*)\n$":if .test(result) then result=.Replace(result,"$1") '恢复空格间距
- end with
- fso.createtextfile("new.txt").write result
- set fso=nothing:set regexp=nothing
复制代码 来个vbs版 |