VBS比较两个文本的内容

http://zhidao.baidu.com/question/1046195367819827299.html?quesup2&oldq=1
文本 1.txt 的内容

接口统计

接收的 发送的

字节 39654715 10281299
单播数据包 56145 49240
非单播数据包 32370 12412
丢弃 0 0
错误 0 0
未知协议 0

文本 2.txt 的内容

接口统计

接收的 发送的

字节 56854715 15651299
单播数据包 534345 494440
非单播数据包 323340 124442
丢弃 0 0
错误 0 0
未知协议 0

现在需要分别比较两个文本中 第五行 (开头:字节) 的大小
56854715 - 39654715 = a

15651299 - 10281299 = b
把 a , b 存到文本 3.txt 中

dim fso,file(1),read(1),list,StringIntercept,readlist,string_handle(1),string_replace,StringIntercept_var,string_compare(1),string_finally,apc_var(1),count
set fso=createobject("scripting.filesystemobject")
file(0)="1.txt" '文件a
file(1)="2.txt" '文件b
find="字节" '查找字符串
count=96 '做个标记
for list=0 to 1 '遍历文件内容
count=count+1
apc_var(list)=chr(count)
 read(list)=fso.opentextfile(file(list)).readall '读取全文
 StringIntercept=split(read(list),vbcrlf) '截取每行
 for each readlist in StringIntercept '遍历每行
  if instr(readlist,find)>0 then '判断是否存在要查找的字符,存在则执行
   string_replace=string_trim(replace(readlist,find,empty),space(1)) '剔除查找到的字符
   StringIntercept_var=split(string_replace,space(1)) '截取两边的数字
   string_handle(0)=string_handle(0)&StringIntercept_var(0)&space(1) '把A与B中的前半部分数字储存到数组A
   string_handle(1)=string_handle(1)&StringIntercept_var(1)&space(1) '把A与B中的后半部分数字储存到数组B
   exit for
  end if
 next 

next
for list=0 to 1 '遍历数组中两个部分的大小
 string_compare(list)=split(string_handle(list),space(1)) '截取空格左右两段落
 if string_compare(list)(0)>string_compare(list)(1) then '判断大小
  string_finally=string_finally&string_compare(list)(0)&" = "& apc_var(list) & vbcrlf '如果A大于B返回A的结果
 else
  string_finally=string_finally&string_compare(list)(1)&" = "& apc_var(list) & vbcrlf '如果A小于B返回B的结果
 end if
next
string_finally=left(string_finally,len(string_finally)-2)
fso.createtextfile("3.txt").write string_finally '写入3.txt文件中
set fso=nothing
 function string_trim(string,Intercept_var) '过滤字符串,剔除多余空格部分
 string=Intercept_var&string
 dim listA
 for listA=1 to len(string)
 if instr(mid(string,listA,1),Intercept_var)=0 then
  if instr(mid(string,listA-1,1),Intercept_var)>0 then
   string_trim=string_trim&Intercept_var
  end if
  string_trim=string_trim&mid(string,listA,1)
 end if
 next
string_trim=right(string_trim,len(string_trim)-1)
end function

温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网